12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790 |
- /* Synaptics Register Mapped Interface (RMI4) I2C Physical Layer Driver.
- * Copyright (c) 2007-2012, Synaptics Incorporated
- *
- * This software is licensed under the terms of the GNU General Public
- * License version 2, as published by the Free Software Foundation, and
- * may be copied, distributed, and modified under those terms.
- *
- * 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.
- *
- */
- #include <linux/kernel.h>
- #include <linux/module.h>
- #include <asm/unaligned.h>
- //#include <mach/cpufreq.h>
- #include <linux/slab.h>
- #include <linux/i2c.h>
- #include <linux/interrupt.h>
- #include <linux/delay.h>
- #include <linux/input.h>
- #include <linux/ctype.h>
- #include <linux/hrtimer.h>
- #include <linux/firmware.h>
- #include "synaptics_i2c_rmi.h"
- #define FACTORY_MODE
- #define CMD_REPORT_TYPE_DELTA 2
- #define CMD_REPORT_TYPE_RAWCAP 20
- #define CMD_GET_REPORT 1
- #define TSP_RAWCAP_MAX 6000
- #define TSP_RAWCAP_MIN 300
- #define TSP_DELTA_MAX 10
- #define TSP_DELTA_MIN -10
- #define WATCHDOG_HRTIMER
- #define WATCHDOG_TIMEOUT_S 2
- #define FORCE_TIMEOUT_100MS 10
- #define STATUS_WORK_INTERVAL 20 /* ms */
- /*
- #define RAW_HEX
- #define HUMAN_READABLE
- */
- #define STATUS_IDLE 0
- #define STATUS_BUSY 1
- #define STATUS_ERROR 2
- #define DATA_REPORT_INDEX_OFFSET 1
- #define DATA_REPORT_DATA_OFFSET 3
- #define COMMAND_GET_REPORT 1
- #define COMMAND_FORCE_CAL 2
- #define COMMAND_FORCE_UPDATE 4
- #define HIGH_RESISTANCE_DATA_SIZE 6
- #define FULL_RAW_CAP_MIN_MAX_DATA_SIZE 4
- #define TREX_DATA_SIZE 7
- #define NO_AUTO_CAL_MASK 0x01
- #define concat(a, b) a##b
- #define tostring(x) (#x)
- #define GROUP(_attrs) {\
- .attrs = _attrs,\
- }
- #define attrify(propname) (&dev_attr_##propname.attr)
- #define show_prototype(propname)\
- static ssize_t concat(synaptics_rmi4_f54, _##propname##_show)(\
- struct device *dev,\
- struct device_attribute *attr,\
- char *buf);\
- \
- struct device_attribute dev_attr_##propname =\
- __ATTR(propname, S_IRUGO,\
- concat(synaptics_rmi4_f54, _##propname##_show),\
- synaptics_rmi4_store_error);
- #define store_prototype(propname)\
- static ssize_t concat(synaptics_rmi4_f54, _##propname##_store)(\
- struct device *dev,\
- struct device_attribute *attr,\
- const char *buf, size_t count);\
- \
- struct device_attribute dev_attr_##propname =\
- __ATTR(propname, S_IWUSR | S_IWGRP,\
- synaptics_rmi4_show_error,\
- concat(synaptics_rmi4_f54, _##propname##_store));
- #define show_store_prototype(propname)\
- static ssize_t concat(synaptics_rmi4_f54, _##propname##_show)(\
- struct device *dev,\
- struct device_attribute *attr,\
- char *buf);\
- \
- static ssize_t concat(synaptics_rmi4_f54, _##propname##_store)(\
- struct device *dev,\
- struct device_attribute *attr,\
- const char *buf, size_t count);\
- \
- struct device_attribute dev_attr_##propname =\
- __ATTR(propname, (S_IRUGO | S_IWUSR | S_IWGRP),\
- concat(synaptics_rmi4_f54, _##propname##_show),\
- concat(synaptics_rmi4_f54, _##propname##_store));
- #define simple_show_func(rtype, propname, fmt)\
- static ssize_t concat(synaptics_rmi4_f54, _##propname##_show)(\
- struct device *dev,\
- struct device_attribute *attr,\
- char *buf)\
- {\
- return snprintf(buf, PAGE_SIZE, fmt, f54->rtype.propname);\
- } \
- #define simple_show_func_unsigned(rtype, propname)\
- simple_show_func(rtype, propname, "%u\n")
- #define show_func(rtype, rgrp, propname, fmt)\
- static ssize_t concat(synaptics_rmi4_f54, _##propname##_show)(\
- struct device *dev,\
- struct device_attribute *attr,\
- char *buf)\
- {\
- int retval;\
- struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;\
- \
- mutex_lock(&f54->rtype##_mutex);\
- \
- retval = f54->fn_ptr->read(rmi4_data,\
- f54->rtype.rgrp->address,\
- f54->rtype.rgrp->data,\
- sizeof(f54->rtype.rgrp->data));\
- mutex_unlock(&f54->rtype##_mutex);\
- if (retval < 0) {\
- dev_err(&rmi4_data->i2c_client->dev,\
- "%s: Failed to read " #rtype\
- " " #rgrp "\n",\
- __func__);\
- return retval;\
- } \
- \
- return snprintf(buf, PAGE_SIZE, fmt,\
- f54->rtype.rgrp->propname);\
- } \
- #define show_store_func(rtype, rgrp, propname, fmt)\
- show_func(rtype, rgrp, propname, fmt)\
- \
- static ssize_t concat(synaptics_rmi4_f54, _##propname##_store)(\
- struct device *dev,\
- struct device_attribute *attr,\
- const char *buf, size_t count)\
- {\
- int retval;\
- unsigned long setting;\
- unsigned long o_setting;\
- struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;\
- \
- retval = kstrtoul(buf, 10, &setting);\
- if (retval)\
- return retval;\
- \
- mutex_lock(&f54->rtype##_mutex);\
- retval = f54->fn_ptr->read(rmi4_data,\
- f54->rtype.rgrp->address,\
- f54->rtype.rgrp->data,\
- sizeof(f54->rtype.rgrp->data));\
- if (retval < 0) {\
- mutex_unlock(&f54->rtype##_mutex);\
- dev_err(&rmi4_data->i2c_client->dev,\
- "%s: Failed to read " #rtype\
- " " #rgrp "\n",\
- __func__);\
- return retval;\
- } \
- \
- if (f54->rtype.rgrp->propname == setting) {\
- mutex_unlock(&f54->rtype##_mutex);\
- return count;\
- } \
- \
- o_setting = f54->rtype.rgrp->propname;\
- f54->rtype.rgrp->propname = setting;\
- \
- retval = f54->fn_ptr->write(rmi4_data,\
- f54->rtype.rgrp->address,\
- f54->rtype.rgrp->data,\
- sizeof(f54->rtype.rgrp->data));\
- if (retval < 0) {\
- dev_err(&rmi4_data->i2c_client->dev,\
- "%s: Failed to write " #rtype\
- " " #rgrp "\n",\
- __func__);\
- f54->rtype.rgrp->propname = o_setting;\
- mutex_unlock(&f54->rtype##_mutex);\
- return retval;\
- } \
- \
- mutex_unlock(&f54->rtype##_mutex);\
- return count;\
- } \
- #define show_store_func_unsigned(rtype, rgrp, propname)\
- show_store_func(rtype, rgrp, propname, "%u\n")
- #define show_replicated_func(rtype, rgrp, propname, fmt)\
- static ssize_t concat(synaptics_rmi4_f54, _##propname##_show)(\
- struct device *dev,\
- struct device_attribute *attr,\
- char *buf)\
- {\
- int retval;\
- int size = 0;\
- unsigned char ii;\
- unsigned char length;\
- unsigned char *temp;\
- struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;\
- \
- mutex_lock(&f54->rtype##_mutex);\
- \
- length = f54->rtype.rgrp->length;\
- \
- retval = f54->fn_ptr->read(rmi4_data,\
- f54->rtype.rgrp->address,\
- (unsigned char *)f54->rtype.rgrp->data,\
- length);\
- mutex_unlock(&f54->rtype##_mutex);\
- if (retval < 0) {\
- dev_dbg(&rmi4_data->i2c_client->dev,\
- "%s: Failed to read " #rtype\
- " " #rgrp "\n",\
- __func__);\
- } \
- \
- temp = buf;\
- \
- for (ii = 0; ii < length; ii++) {\
- retval = snprintf(temp, PAGE_SIZE - size, fmt " ",\
- f54->rtype.rgrp->data[ii].propname);\
- if (retval < 0) {\
- dev_err(&rmi4_data->i2c_client->dev,\
- "%s: Faild to write output\n",\
- __func__);\
- return retval;\
- } \
- size += retval;\
- temp += retval;\
- } \
- \
- retval = snprintf(temp, PAGE_SIZE - size, "\n");\
- if (retval < 0) {\
- dev_err(&rmi4_data->i2c_client->dev,\
- "%s: Faild to write null terminator\n",\
- __func__);\
- return retval;\
- } \
- \
- return size + retval;\
- } \
- #define show_replicated_func_unsigned(rtype, rgrp, propname)\
- show_replicated_func(rtype, rgrp, propname, "%u")
- #define show_store_replicated_func(rtype, rgrp, propname, fmt)\
- show_replicated_func(rtype, rgrp, propname, fmt)\
- \
- static ssize_t concat(synaptics_rmi4_f54, _##propname##_store)(\
- struct device *dev,\
- struct device_attribute *attr,\
- const char *buf, size_t count)\
- {\
- int retval;\
- unsigned int setting;\
- unsigned char ii;\
- unsigned char length;\
- const unsigned char *temp;\
- struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;\
- \
- mutex_lock(&f54->rtype##_mutex);\
- \
- length = f54->rtype.rgrp->length;\
- \
- retval = f54->fn_ptr->read(rmi4_data,\
- f54->rtype.rgrp->address,\
- (unsigned char *)f54->rtype.rgrp->data,\
- length);\
- if (retval < 0) {\
- dev_dbg(&rmi4_data->i2c_client->dev,\
- "%s: Failed to read " #rtype\
- " " #rgrp "\n",\
- __func__);\
- } \
- \
- temp = buf;\
- \
- for (ii = 0; ii < length; ii++) {\
- if (sscanf(temp, fmt, &setting) == 1) {\
- f54->rtype.rgrp->data[ii].propname = setting;\
- } else {\
- retval = f54->fn_ptr->read(rmi4_data,\
- f54->rtype.rgrp->address,\
- (unsigned char *)f54->rtype.rgrp->data,\
- length);\
- mutex_unlock(&f54->rtype##_mutex);\
- return -EINVAL;\
- } \
- \
- while (*temp != 0) {\
- temp++;\
- if (isspace(*(temp - 1)) && !isspace(*temp))\
- break;\
- } \
- } \
- \
- retval = f54->fn_ptr->write(rmi4_data,\
- f54->rtype.rgrp->address,\
- (unsigned char *)f54->rtype.rgrp->data,\
- length);\
- mutex_unlock(&f54->rtype##_mutex);\
- if (retval < 0) {\
- dev_err(&rmi4_data->i2c_client->dev,\
- "%s: Failed to write " #rtype\
- " " #rgrp "\n",\
- __func__);\
- return retval;\
- } \
- \
- return count;\
- } \
- #define show_store_replicated_func_unsigned(rtype, rgrp, propname)\
- show_store_replicated_func(rtype, rgrp, propname, "%u")
- enum f54_report_types {
- F54_8BIT_IMAGE = 1,
- F54_16BIT_IMAGE = 2,
- F54_RAW_16BIT_IMAGE = 3,
- F54_HIGH_RESISTANCE = 4,
- F54_TX_TO_TX_SHORT = 5,
- F54_RX_TO_RX1 = 7,
- F54_TRUE_BASELINE = 9,
- F54_FULL_RAW_CAP_MIN_MAX = 13,
- F54_RX_OPENS1 = 14,
- F54_TX_OPEN = 15,
- F54_TX_TO_GROUND = 16,
- F54_RX_TO_RX2 = 17,
- F54_RX_OPENS2 = 18,
- F54_FULL_RAW_CAP = 19,
- F54_FULL_RAW_CAP_RX_COUPLING_COMP = 20,
- F54_SENSOR_SPEED = 22,
- F54_ADC_RANGE = 23,
- F54_TREX_OPENS = 24,
- F54_TREX_TO_GND = 25,
- F54_TREX_SHORTS = 26,
- F54_ABS_RAW_CAP = 38,
- F54_ABS_DELTA_CAP = 40,
- INVALID_REPORT_TYPE = -1,
- };
- struct f54_query {
- union {
- struct {
- /* query 0 */
- unsigned char num_of_rx_electrodes;
- /* query 1 */
- unsigned char num_of_tx_electrodes;
- /* query 2 */
- unsigned char f54_query2_b0__1:2;
- unsigned char has_baseline:1;
- unsigned char has_image8:1;
- unsigned char f54_query2_b4__5:2;
- unsigned char has_image16:1;
- unsigned char f54_query2_b7:1;
- /* queries 3.0 and 3.1 */
- unsigned short clock_rate;
- /* query 4 */
- unsigned char touch_controller_family;
- /* query 5 */
- unsigned char has_pixel_touch_threshold_adjustment:1;
- unsigned char f54_query5_b1__7:7;
- /* query 6 */
- unsigned char has_sensor_assignment:1;
- unsigned char has_interference_metric:1;
- unsigned char has_sense_frequency_control:1;
- unsigned char has_firmware_noise_mitigation:1;
- unsigned char has_ctrl11:1;
- unsigned char has_two_byte_report_rate:1;
- unsigned char has_one_byte_report_rate:1;
- unsigned char has_relaxation_control:1;
- /* query 7 */
- unsigned char curve_compensation_mode:2;
- unsigned char f54_query7_b2__7:6;
- /* query 8 */
- unsigned char f54_query8_b0:1;
- unsigned char has_iir_filter:1;
- unsigned char has_cmn_removal:1;
- unsigned char has_cmn_maximum:1;
- unsigned char has_touch_hysteresis:1;
- unsigned char has_edge_compensation:1;
- unsigned char has_per_frequency_noise_control:1;
- unsigned char has_enhanced_stretch:1;
- /* query 9 */
- unsigned char has_force_fast_relaxation:1;
- unsigned char has_multi_metric_state_machine:1;
- unsigned char has_signal_clarity:1;
- unsigned char has_variance_metric:1;
- unsigned char has_0d_relaxation_control:1;
- unsigned char has_0d_acquisition_control:1;
- unsigned char has_status:1;
- unsigned char has_slew_metric:1;
- /* queries 10 11 */
- unsigned char f54_query10;
- unsigned char f54_query11;
- /* query 12 */
- unsigned char number_of_sensing_frequencies:4;
- unsigned char f54_query12_b4__7:4;
- } __packed;
- unsigned char data[14];
- };
- };
- struct f54_control_0 {
- union {
- struct {
- unsigned char no_relax:1;
- unsigned char no_scan:1;
- unsigned char force_fast_relaxation:1;
- unsigned char startup_fast_relaxation:1;
- unsigned char gesture_cancels_sfr:1;
- unsigned char enable_energy_ratio_relaxation:1;
- unsigned char excessive_noise_attn_enable:1;
- unsigned char f54_control0_b7:1;
- } __packed;
- struct {
- unsigned char data[1];
- unsigned short address;
- } __packed;
- };
- };
- struct f54_control_1 {
- union {
- struct {
- unsigned char bursts_per_cluster:4;
- unsigned char f54_ctrl1_b4__7:4;
- } __packed;
- struct {
- unsigned char data[1];
- unsigned short address;
- } __packed;
- };
- };
- struct f54_control_2 {
- union {
- struct {
- unsigned short saturation_cap;
- } __packed;
- struct {
- unsigned char data[2];
- unsigned short address;
- } __packed;
- };
- };
- struct f54_control_3 {
- union {
- struct {
- unsigned char pixel_touch_threshold;
- } __packed;
- struct {
- unsigned char data[1];
- unsigned short address;
- } __packed;
- };
- };
- struct f54_control_4__6 {
- union {
- struct {
- /* control 4 */
- unsigned char rx_feedback_cap:2;
- unsigned char bias_current:2;
- unsigned char f54_ctrl4_b4__7:4;
- /* control 5 */
- unsigned char low_ref_cap:2;
- unsigned char low_ref_feedback_cap:2;
- unsigned char low_ref_polarity:1;
- unsigned char f54_ctrl5_b5__7:3;
- /* control 6 */
- unsigned char high_ref_cap:2;
- unsigned char high_ref_feedback_cap:2;
- unsigned char high_ref_polarity:1;
- unsigned char f54_ctrl6_b5__7:3;
- } __packed;
- struct {
- unsigned char data[3];
- unsigned short address;
- } __packed;
- };
- };
- struct f54_control_7 {
- union {
- struct {
- unsigned char cbc_cap:2;
- unsigned char cbc_polarity:2;
- unsigned char cbc_tx_carrier_selection:1;
- unsigned char f54_ctrl7_b5__7:3;
- } __packed;
- struct {
- unsigned char data[1];
- unsigned short address;
- } __packed;
- };
- };
- struct f54_control_8__9 {
- union {
- struct {
- /* control 8 */
- unsigned short integration_duration:10;
- unsigned short f54_ctrl8_b10__15:6;
- /* control 9 */
- unsigned char reset_duration;
- } __packed;
- struct {
- unsigned char data[3];
- unsigned short address;
- } __packed;
- };
- };
- struct f54_control_10 {
- union {
- struct {
- unsigned char noise_sensing_bursts_per_image:4;
- unsigned char f54_ctrl10_b4__7:4;
- } __packed;
- struct {
- unsigned char data[1];
- unsigned short address;
- } __packed;
- };
- };
- struct f54_control_11 {
- union {
- struct {
- unsigned short f54_ctrl11;
- } __packed;
- struct {
- unsigned char data[2];
- unsigned short address;
- } __packed;
- };
- };
- struct f54_control_12__13 {
- union {
- struct {
- /* control 12 */
- unsigned char slow_relaxation_rate;
- /* control 13 */
- unsigned char fast_relaxation_rate;
- } __packed;
- struct {
- unsigned char data[2];
- unsigned short address;
- } __packed;
- };
- };
- struct f54_control_14 {
- union {
- struct {
- unsigned char rxs_on_xaxis:1;
- unsigned char curve_comp_on_txs:1;
- unsigned char f54_ctrl14_b2__7:6;
- } __packed;
- struct {
- unsigned char data[1];
- unsigned short address;
- } __packed;
- };
- };
- struct f54_control_15n {
- unsigned char sensor_rx_assignment;
- };
- struct f54_control_15 {
- struct f54_control_15n *data;
- unsigned short address;
- unsigned char length;
- };
- struct f54_control_16n {
- unsigned char sensor_tx_assignment;
- };
- struct f54_control_16 {
- struct f54_control_16n *data;
- unsigned short address;
- unsigned char length;
- };
- struct f54_control_17n {
- unsigned char burst_count_b8__10:3;
- unsigned char disable:1;
- unsigned char f54_ctrl17_b4:1;
- unsigned char filter_bandwidth:3;
- };
- struct f54_control_17 {
- struct f54_control_17n *data;
- unsigned short address;
- unsigned char length;
- };
- struct f54_control_18n {
- unsigned char burst_count_b0__7;
- };
- struct f54_control_18 {
- struct f54_control_18n *data;
- unsigned short address;
- unsigned char length;
- };
- struct f54_control_19n {
- unsigned char stretch_duration;
- };
- struct f54_control_19 {
- struct f54_control_19n *data;
- unsigned short address;
- unsigned char length;
- };
- struct f54_control_20 {
- union {
- struct {
- unsigned char disable_noise_mitigation:1;
- unsigned char f54_ctrl20_b1__7:7;
- } __packed;
- struct {
- unsigned char data[1];
- unsigned short address;
- } __packed;
- };
- };
- struct f54_control_21 {
- union {
- struct {
- unsigned short freq_shift_noise_threshold;
- } __packed;
- struct {
- unsigned char data[2];
- unsigned short address;
- } __packed;
- };
- };
- struct f54_control_22__26 {
- union {
- struct {
- /* control 22 */
- unsigned char f54_ctrl22;
- /* control 23 */
- unsigned short medium_noise_threshold;
- /* control 24 */
- unsigned short high_noise_threshold;
- /* control 25 */
- unsigned char noise_density;
- /* control 26 */
- unsigned char frame_count;
- } __packed;
- struct {
- unsigned char data[7];
- unsigned short address;
- } __packed;
- };
- };
- struct f54_control_27 {
- union {
- struct {
- unsigned char iir_filter_coef;
- } __packed;
- struct {
- unsigned char data[1];
- unsigned short address;
- } __packed;
- };
- };
- struct f54_control_28 {
- union {
- struct {
- unsigned short quiet_threshold;
- } __packed;
- struct {
- unsigned char data[2];
- unsigned short address;
- } __packed;
- };
- };
- struct f54_control_29 {
- union {
- struct {
- /* control 29 */
- unsigned char f54_ctrl29_b0__6:7;
- unsigned char cmn_filter_disable:1;
- } __packed;
- struct {
- unsigned char data[1];
- unsigned short address;
- } __packed;
- };
- };
- struct f54_control_30 {
- union {
- struct {
- unsigned char cmn_filter_max;
- } __packed;
- struct {
- unsigned char data[1];
- unsigned short address;
- } __packed;
- };
- };
- struct f54_control_31 {
- union {
- struct {
- unsigned char touch_hysteresis;
- } __packed;
- struct {
- unsigned char data[1];
- unsigned short address;
- } __packed;
- };
- };
- struct f54_control_32__35 {
- union {
- struct {
- /* control 32 */
- unsigned short rx_low_edge_comp;
- /* control 33 */
- unsigned short rx_high_edge_comp;
- /* control 34 */
- unsigned short tx_low_edge_comp;
- /* control 35 */
- unsigned short tx_high_edge_comp;
- } __packed;
- struct {
- unsigned char data[8];
- unsigned short address;
- } __packed;
- };
- };
- struct f54_control_36n {
- unsigned char axis1_comp;
- };
- struct f54_control_36 {
- struct f54_control_36n *data;
- unsigned short address;
- unsigned char length;
- };
- struct f54_control_37n {
- unsigned char axis2_comp;
- };
- struct f54_control_37 {
- struct f54_control_37n *data;
- unsigned short address;
- unsigned char length;
- };
- struct f54_control_38n {
- unsigned char noise_control_1;
- };
- struct f54_control_38 {
- struct f54_control_38n *data;
- unsigned short address;
- unsigned char length;
- };
- struct f54_control_39n {
- unsigned char noise_control_2;
- };
- struct f54_control_39 {
- struct f54_control_39n *data;
- unsigned short address;
- unsigned char length;
- };
- struct f54_control_40n {
- unsigned char noise_control_3;
- };
- struct f54_control_40 {
- struct f54_control_40n *data;
- unsigned short address;
- unsigned char length;
- };
- struct f54_control_41 {
- union {
- struct {
- /* control 41 */
- unsigned char no_signal_clarity:1;
- unsigned char f54_ctrl41_b1__7:7;
- } __packed;
- struct {
- unsigned char data[1];
- unsigned short address;
- } __packed;
- };
- };
- struct f54_control_57 {
- union {
- struct {
- unsigned char cbc_cap_0d:3;
- unsigned char cbc_polarity_0d:1;
- unsigned char cbc_tx_carrier_selection_0d:1;
- unsigned char f54_ctrl57_b5__7:3;
- } __packed;
- struct {
- unsigned char data[1];
- unsigned short address;
- } __packed;
- };
- };
- struct f54_control {
- struct f54_control_0 *reg_0;
- struct f54_control_1 *reg_1;
- struct f54_control_2 *reg_2;
- struct f54_control_3 *reg_3;
- struct f54_control_4__6 *reg_4__6;
- struct f54_control_7 *reg_7;
- struct f54_control_8__9 *reg_8__9;
- struct f54_control_10 *reg_10;
- struct f54_control_11 *reg_11;
- struct f54_control_12__13 *reg_12__13;
- struct f54_control_14 *reg_14;
- struct f54_control_15 *reg_15;
- struct f54_control_16 *reg_16;
- struct f54_control_17 *reg_17;
- struct f54_control_18 *reg_18;
- struct f54_control_19 *reg_19;
- struct f54_control_20 *reg_20;
- struct f54_control_21 *reg_21;
- struct f54_control_22__26 *reg_22__26;
- struct f54_control_27 *reg_27;
- struct f54_control_28 *reg_28;
- struct f54_control_29 *reg_29;
- struct f54_control_30 *reg_30;
- struct f54_control_31 *reg_31;
- struct f54_control_32__35 *reg_32__35;
- struct f54_control_36 *reg_36;
- struct f54_control_37 *reg_37;
- struct f54_control_38 *reg_38;
- struct f54_control_39 *reg_39;
- struct f54_control_40 *reg_40;
- struct f54_control_41 *reg_41;
- struct f54_control_57 *reg_57;
- };
- #ifdef FACTORY_MODE
- #include <linux/uaccess.h>
- #define CMD_STR_LEN 32
- #define CMD_PARAM_NUM 8
- #define CMD_RESULT_STR_LEN 896
- #define FT_CMD(name, func) .cmd_name = name, .cmd_func = func
- #define F12_CTRL15_ADDR 0x0015
- enum CMD_STATUS {
- CMD_STATUS_WAITING = 0,
- CMD_STATUS_RUNNING,
- CMD_STATUS_OK,
- CMD_STATUS_FAIL,
- CMD_STATUS_NOT_APPLICABLE,
- };
- struct ft_cmd {
- const char *cmd_name;
- void (*cmd_func)(void);
- struct list_head list;
- };
- struct factory_data {
- struct device *fac_dev_ts;
- short *rawcap_data;
- short *delta_data;
- short *abscap_data;
- short *absdelta_data;
- short *trx_short;
- bool cmd_is_running;
- unsigned char cmd_state;
- char cmd[CMD_STR_LEN];
- int cmd_param[CMD_PARAM_NUM];
- char cmd_buff[CMD_RESULT_STR_LEN];
- char cmd_result[CMD_RESULT_STR_LEN];
- struct mutex cmd_lock;
- struct list_head cmd_list_head;
- };
- extern void synaptics_power_ctrl(struct synaptics_rmi4_data *rmi4_data, bool enable);
- static int synaptics_rmi4_f54_get_report_type(int type);
- static ssize_t cmd_store(struct device *dev, struct device_attribute *attr,
- const char *buf, size_t count);
- static ssize_t cmd_status_show(struct device *dev,
- struct device_attribute *attr, char *buf);
- static ssize_t cmd_result_show(struct device *dev,
- struct device_attribute *attr, char *buf);
- static ssize_t cmd_list_show(struct device *dev,
- struct device_attribute *attr, char *buf);
- static DEVICE_ATTR(cmd, S_IWUSR | S_IWGRP, NULL, cmd_store);
- static DEVICE_ATTR(cmd_status, S_IRUGO, cmd_status_show, NULL);
- static DEVICE_ATTR(cmd_result, S_IRUGO, cmd_result_show, NULL);
- static DEVICE_ATTR(cmd_list, S_IRUGO, cmd_list_show, NULL);
- static struct attribute *cmd_attributes[] = {
- &dev_attr_cmd.attr,
- &dev_attr_cmd_status.attr,
- &dev_attr_cmd_result.attr,
- &dev_attr_cmd_list.attr,
- NULL,
- };
- static struct attribute_group cmd_attr_group = {
- .attrs = cmd_attributes,
- };
- static void fw_update(void);
- static void get_fw_ver_bin(void);
- static void get_fw_ver_ic(void);
- static void get_fac_fw_ver_bin(void);
- static void get_config_ver(void);
- static void get_threshold(void);
- static void module_off_master(void);
- static void module_on_master(void);
- static void get_chip_vendor(void);
- static void get_chip_name(void);
- static void get_x_num(void);
- static void get_y_num(void);
- static void get_rawcap(void);
- static void run_rawcap_read(void);
- static void get_delta(void);
- static void run_delta_read(void);
- static void run_abscap_read(void);
- static void run_absdelta_read(void);
- static void run_trx_short_test(void);
- static void hover_enable(void);
- static void hover_no_sleep_enable(void);
- #ifdef CONFIG_GLOVE_TOUCH
- static void glove_mode(void);
- static void clear_cover_mode(void);
- static void get_glove_sensitivity(void);
- static void fast_glove_mode(void);
- #endif
- #ifdef TSP_BOOSTER
- static void boost_level(void);
- #endif
- static void switch_sel(void);
- static void not_support_cmd(void);
- struct ft_cmd ft_cmds[] = {
- {FT_CMD("fw_update", fw_update),},
- {FT_CMD("get_fw_ver_bin", get_fw_ver_bin),},
- {FT_CMD("get_fw_ver_ic", get_fw_ver_ic),},
- {FT_CMD("get_fac_fw_ver_bin", get_fac_fw_ver_bin),},
- {FT_CMD("get_config_ver", get_config_ver),},
- {FT_CMD("get_threshold", get_threshold),},
- {FT_CMD("module_off_master", module_off_master),},
- {FT_CMD("module_on_master", module_on_master),},
- {FT_CMD("module_off_slave", not_support_cmd),},
- {FT_CMD("module_on_slave", not_support_cmd),},
- {FT_CMD("get_chip_vendor", get_chip_vendor),},
- {FT_CMD("get_chip_name", get_chip_name),},
- {FT_CMD("get_x_num", get_x_num),},
- {FT_CMD("get_y_num", get_y_num),},
- {FT_CMD("get_rawcap", get_rawcap),},
- {FT_CMD("run_rawcap_read", run_rawcap_read),},
- {FT_CMD("get_delta", get_delta),},
- {FT_CMD("run_delta_read", run_delta_read),},
- {FT_CMD("run_abscap_read", run_abscap_read),},
- {FT_CMD("run_absdelta_read", run_absdelta_read),},
- {FT_CMD("run_trx_short_test", run_trx_short_test),},
- {FT_CMD("hover_enable", hover_enable),},
- {FT_CMD("hover_no_sleep_enable", hover_no_sleep_enable),},
- #ifdef CONFIG_GLOVE_TOUCH
- {FT_CMD("glove_mode", glove_mode),},
- {FT_CMD("clear_cover_mode", clear_cover_mode),},
- {FT_CMD("get_glove_sensitivity", get_glove_sensitivity),},
- {FT_CMD("fast_glove_mode", fast_glove_mode),},
- #endif
- #ifdef TSP_BOOSTER
- {FT_CMD("boost_level", boost_level),},
- #endif
- {FT_CMD("switch_sel", switch_sel),},
- {FT_CMD("not_support_cmd", not_support_cmd),},
- };
- #endif
- struct synaptics_rmi4_f54_handle {
- bool no_auto_cal;
- unsigned char status;
- unsigned char intr_mask;
- unsigned char intr_reg_num;
- unsigned char *report_data;
- unsigned short query_base_addr;
- unsigned short control_base_addr;
- unsigned short data_base_addr;
- unsigned short command_base_addr;
- unsigned short fifoindex;
- unsigned int report_size;
- unsigned int data_buffer_size;
- enum f54_report_types report_type;
- struct mutex status_mutex;
- struct mutex data_mutex;
- struct mutex control_mutex;
- struct f54_query query;
- struct f54_control control;
- #ifdef FACTORY_MODE
- struct factory_data *factory_data;
- #endif
- struct kobject *attr_dir;
- struct hrtimer watchdog;
- struct work_struct timeout_work;
- struct delayed_work status_work;
- struct workqueue_struct *status_workqueue;
- struct synaptics_rmi4_exp_fn_ptr *fn_ptr;
- struct synaptics_rmi4_data *rmi4_data;
- };
- show_prototype(status)
- show_prototype(report_size)
- show_store_prototype(no_auto_cal)
- show_store_prototype(report_type)
- show_store_prototype(fifoindex)
- store_prototype(do_preparation)
- store_prototype(get_report)
- store_prototype(force_cal)
- show_prototype(num_of_rx_electrodes)
- show_prototype(num_of_tx_electrodes)
- show_prototype(has_image16)
- show_prototype(has_image8)
- show_prototype(has_baseline)
- show_prototype(clock_rate)
- show_prototype(touch_controller_family)
- show_prototype(has_pixel_touch_threshold_adjustment)
- show_prototype(has_sensor_assignment)
- show_prototype(has_interference_metric)
- show_prototype(has_sense_frequency_control)
- show_prototype(has_firmware_noise_mitigation)
- show_prototype(has_two_byte_report_rate)
- show_prototype(has_one_byte_report_rate)
- show_prototype(has_relaxation_control)
- show_prototype(curve_compensation_mode)
- show_prototype(has_iir_filter)
- show_prototype(has_cmn_removal)
- show_prototype(has_cmn_maximum)
- show_prototype(has_touch_hysteresis)
- show_prototype(has_edge_compensation)
- show_prototype(has_per_frequency_noise_control)
- show_prototype(has_signal_clarity)
- show_prototype(number_of_sensing_frequencies)
- show_store_prototype(no_relax)
- show_store_prototype(no_scan)
- show_store_prototype(bursts_per_cluster)
- show_store_prototype(saturation_cap)
- show_store_prototype(pixel_touch_threshold)
- show_store_prototype(rx_feedback_cap)
- show_store_prototype(low_ref_cap)
- show_store_prototype(low_ref_feedback_cap)
- show_store_prototype(low_ref_polarity)
- show_store_prototype(high_ref_cap)
- show_store_prototype(high_ref_feedback_cap)
- show_store_prototype(high_ref_polarity)
- show_store_prototype(cbc_cap)
- show_store_prototype(cbc_polarity)
- show_store_prototype(cbc_tx_carrier_selection)
- show_store_prototype(integration_duration)
- show_store_prototype(reset_duration)
- show_store_prototype(noise_sensing_bursts_per_image)
- show_store_prototype(slow_relaxation_rate)
- show_store_prototype(fast_relaxation_rate)
- show_store_prototype(rxs_on_xaxis)
- show_store_prototype(curve_comp_on_txs)
- show_prototype(sensor_rx_assignment)
- show_prototype(sensor_tx_assignment)
- show_prototype(burst_count)
- show_prototype(disable)
- show_prototype(filter_bandwidth)
- show_prototype(stretch_duration)
- show_store_prototype(disable_noise_mitigation)
- show_store_prototype(freq_shift_noise_threshold)
- show_store_prototype(medium_noise_threshold)
- show_store_prototype(high_noise_threshold)
- show_store_prototype(noise_density)
- show_store_prototype(frame_count)
- show_store_prototype(iir_filter_coef)
- show_store_prototype(quiet_threshold)
- show_store_prototype(cmn_filter_disable)
- show_store_prototype(cmn_filter_max)
- show_store_prototype(touch_hysteresis)
- show_store_prototype(rx_low_edge_comp)
- show_store_prototype(rx_high_edge_comp)
- show_store_prototype(tx_low_edge_comp)
- show_store_prototype(tx_high_edge_comp)
- show_store_prototype(axis1_comp)
- show_store_prototype(axis2_comp)
- show_prototype(noise_control_1)
- show_prototype(noise_control_2)
- show_prototype(noise_control_3)
- show_store_prototype(no_signal_clarity)
- static ssize_t synaptics_rmi4_f54_data_read(struct file *data_file,
- struct kobject *kobj, struct bin_attribute *attributes,
- char *buf, loff_t pos, size_t count);
- static struct attribute *attrs[] = {
- attrify(status),
- attrify(report_size),
- attrify(no_auto_cal),
- attrify(report_type),
- attrify(fifoindex),
- attrify(do_preparation),
- attrify(get_report),
- attrify(force_cal),
- attrify(num_of_rx_electrodes),
- attrify(num_of_tx_electrodes),
- attrify(has_image16),
- attrify(has_image8),
- attrify(has_baseline),
- attrify(clock_rate),
- attrify(touch_controller_family),
- attrify(has_pixel_touch_threshold_adjustment),
- attrify(has_sensor_assignment),
- attrify(has_interference_metric),
- attrify(has_sense_frequency_control),
- attrify(has_firmware_noise_mitigation),
- attrify(has_two_byte_report_rate),
- attrify(has_one_byte_report_rate),
- attrify(has_relaxation_control),
- attrify(curve_compensation_mode),
- attrify(has_iir_filter),
- attrify(has_cmn_removal),
- attrify(has_cmn_maximum),
- attrify(has_touch_hysteresis),
- attrify(has_edge_compensation),
- attrify(has_per_frequency_noise_control),
- attrify(has_signal_clarity),
- attrify(number_of_sensing_frequencies),
- NULL,
- };
- static struct attribute_group attr_group = GROUP(attrs);
- static struct attribute *attrs_reg_0[] = {
- attrify(no_relax),
- attrify(no_scan),
- NULL,
- };
- static struct attribute *attrs_reg_1[] = {
- attrify(bursts_per_cluster),
- NULL,
- };
- static struct attribute *attrs_reg_2[] = {
- attrify(saturation_cap),
- NULL,
- };
- static struct attribute *attrs_reg_3[] = {
- attrify(pixel_touch_threshold),
- NULL,
- };
- static struct attribute *attrs_reg_4__6[] = {
- attrify(rx_feedback_cap),
- attrify(low_ref_cap),
- attrify(low_ref_feedback_cap),
- attrify(low_ref_polarity),
- attrify(high_ref_cap),
- attrify(high_ref_feedback_cap),
- attrify(high_ref_polarity),
- NULL,
- };
- static struct attribute *attrs_reg_7[] = {
- attrify(cbc_cap),
- attrify(cbc_polarity),
- attrify(cbc_tx_carrier_selection),
- NULL,
- };
- static struct attribute *attrs_reg_8__9[] = {
- attrify(integration_duration),
- attrify(reset_duration),
- NULL,
- };
- static struct attribute *attrs_reg_10[] = {
- attrify(noise_sensing_bursts_per_image),
- NULL,
- };
- static struct attribute *attrs_reg_11[] = {
- NULL,
- };
- static struct attribute *attrs_reg_12__13[] = {
- attrify(slow_relaxation_rate),
- attrify(fast_relaxation_rate),
- NULL,
- };
- static struct attribute *attrs_reg_14__16[] = {
- attrify(rxs_on_xaxis),
- attrify(curve_comp_on_txs),
- attrify(sensor_rx_assignment),
- attrify(sensor_tx_assignment),
- NULL,
- };
- static struct attribute *attrs_reg_17__19[] = {
- attrify(burst_count),
- attrify(disable),
- attrify(filter_bandwidth),
- attrify(stretch_duration),
- NULL,
- };
- static struct attribute *attrs_reg_20[] = {
- attrify(disable_noise_mitigation),
- NULL,
- };
- static struct attribute *attrs_reg_21[] = {
- attrify(freq_shift_noise_threshold),
- NULL,
- };
- static struct attribute *attrs_reg_22__26[] = {
- attrify(medium_noise_threshold),
- attrify(high_noise_threshold),
- attrify(noise_density),
- attrify(frame_count),
- NULL,
- };
- static struct attribute *attrs_reg_27[] = {
- attrify(iir_filter_coef),
- NULL,
- };
- static struct attribute *attrs_reg_28[] = {
- attrify(quiet_threshold),
- NULL,
- };
- static struct attribute *attrs_reg_29[] = {
- attrify(cmn_filter_disable),
- NULL,
- };
- static struct attribute *attrs_reg_30[] = {
- attrify(cmn_filter_max),
- NULL,
- };
- static struct attribute *attrs_reg_31[] = {
- attrify(touch_hysteresis),
- NULL,
- };
- static struct attribute *attrs_reg_32__35[] = {
- attrify(rx_low_edge_comp),
- attrify(rx_high_edge_comp),
- attrify(tx_low_edge_comp),
- attrify(tx_high_edge_comp),
- NULL,
- };
- static struct attribute *attrs_reg_36[] = {
- attrify(axis1_comp),
- NULL,
- };
- static struct attribute *attrs_reg_37[] = {
- attrify(axis2_comp),
- NULL,
- };
- static struct attribute *attrs_reg_38__40[] = {
- attrify(noise_control_1),
- attrify(noise_control_2),
- attrify(noise_control_3),
- NULL,
- };
- static struct attribute *attrs_reg_41[] = {
- attrify(no_signal_clarity),
- NULL,
- };
- static struct attribute_group attrs_ctrl_regs[] = {
- GROUP(attrs_reg_0),
- GROUP(attrs_reg_1),
- GROUP(attrs_reg_2),
- GROUP(attrs_reg_3),
- GROUP(attrs_reg_4__6),
- GROUP(attrs_reg_7),
- GROUP(attrs_reg_8__9),
- GROUP(attrs_reg_10),
- GROUP(attrs_reg_11),
- GROUP(attrs_reg_12__13),
- GROUP(attrs_reg_14__16),
- GROUP(attrs_reg_17__19),
- GROUP(attrs_reg_20),
- GROUP(attrs_reg_21),
- GROUP(attrs_reg_22__26),
- GROUP(attrs_reg_27),
- GROUP(attrs_reg_28),
- GROUP(attrs_reg_29),
- GROUP(attrs_reg_30),
- GROUP(attrs_reg_31),
- GROUP(attrs_reg_32__35),
- GROUP(attrs_reg_36),
- GROUP(attrs_reg_37),
- GROUP(attrs_reg_38__40),
- GROUP(attrs_reg_41),
- };
- static bool attrs_ctrl_regs_exist[ARRAY_SIZE(attrs_ctrl_regs)];
- static struct bin_attribute dev_report_data = {
- .attr = {
- .name = "report_data",
- .mode = S_IRUGO,
- },
- .size = 0,
- .read = synaptics_rmi4_f54_data_read,
- };
- static struct synaptics_rmi4_f54_handle *f54;
- static bool is_report_type_valid(enum f54_report_types report_type)
- {
- switch (report_type) {
- case F54_8BIT_IMAGE:
- case F54_16BIT_IMAGE:
- case F54_RAW_16BIT_IMAGE:
- case F54_HIGH_RESISTANCE:
- case F54_TX_TO_TX_SHORT:
- case F54_RX_TO_RX1:
- case F54_TRUE_BASELINE:
- case F54_FULL_RAW_CAP_MIN_MAX:
- case F54_RX_OPENS1:
- case F54_TX_OPEN:
- case F54_TX_TO_GROUND:
- case F54_RX_TO_RX2:
- case F54_RX_OPENS2:
- case F54_FULL_RAW_CAP:
- case F54_FULL_RAW_CAP_RX_COUPLING_COMP:
- case F54_SENSOR_SPEED:
- case F54_ADC_RANGE:
- case F54_TREX_OPENS:
- case F54_TREX_TO_GND:
- case F54_TREX_SHORTS:
- case F54_ABS_RAW_CAP:
- case F54_ABS_DELTA_CAP:
- return true;
- break;
- default:
- f54->report_type = INVALID_REPORT_TYPE;
- f54->report_size = 0;
- return false;
- }
- }
- static void set_report_size(void)
- {
- int retval;
- unsigned char rx = f54->rmi4_data->num_of_rx;
- unsigned char tx = f54->rmi4_data->num_of_tx;
- struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
- switch (f54->report_type) {
- case F54_8BIT_IMAGE:
- f54->report_size = rx * tx;
- break;
- case F54_16BIT_IMAGE:
- case F54_RAW_16BIT_IMAGE:
- case F54_TRUE_BASELINE:
- case F54_FULL_RAW_CAP:
- case F54_FULL_RAW_CAP_RX_COUPLING_COMP:
- case F54_SENSOR_SPEED:
- f54->report_size = 2 * rx * tx;
- break;
- case F54_HIGH_RESISTANCE:
- f54->report_size = HIGH_RESISTANCE_DATA_SIZE;
- break;
- case F54_TX_TO_TX_SHORT:
- case F54_TX_OPEN:
- case F54_TX_TO_GROUND:
- f54->report_size = (tx + 7) / 8;
- break;
- case F54_RX_TO_RX1:
- case F54_RX_OPENS1:
- if (rx < tx)
- f54->report_size = 2 * rx * rx;
- else
- f54->report_size = 2 * rx * tx;
- break;
- case F54_FULL_RAW_CAP_MIN_MAX:
- f54->report_size = FULL_RAW_CAP_MIN_MAX_DATA_SIZE;
- break;
- case F54_RX_TO_RX2:
- case F54_RX_OPENS2:
- if (rx <= tx)
- f54->report_size = 0;
- else
- f54->report_size = 2 * rx * (rx - tx);
- break;
- case F54_ADC_RANGE:
- if (f54->query.has_signal_clarity) {
- mutex_lock(&f54->control_mutex);
- retval = f54->fn_ptr->read(rmi4_data,
- f54->control.reg_41->address,
- f54->control.reg_41->data,
- sizeof(f54->control.reg_41->data));
- mutex_unlock(&f54->control_mutex);
- if (retval < 0) {
- dev_dbg(&rmi4_data->i2c_client->dev,
- "%s: Failed to read control reg_41\n",
- __func__);
- f54->report_size = 0;
- break;
- }
- if (!f54->control.reg_41->no_signal_clarity) {
- if (tx % 4)
- tx += 4 - (tx % 4);
- }
- }
- f54->report_size = 2 * rx * tx;
- break;
- case F54_TREX_OPENS:
- case F54_TREX_TO_GND:
- case F54_TREX_SHORTS:
- f54->report_size = TREX_DATA_SIZE;
- break;
- case F54_ABS_RAW_CAP:
- case F54_ABS_DELTA_CAP:
- f54->report_size = 4 * (rx + tx);
- break;
- default:
- f54->report_size = 0;
- }
- return;
- }
- static int set_interrupt(bool set)
- {
- int retval;
- unsigned char ii;
- unsigned char zero = 0x00;
- unsigned char *intr_mask;
- unsigned short f01_ctrl_reg;
- struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
- intr_mask = rmi4_data->intr_mask;
- f01_ctrl_reg = rmi4_data->f01_ctrl_base_addr + 1 + f54->intr_reg_num;
- if (!set) {
- retval = f54->fn_ptr->write(rmi4_data,
- f01_ctrl_reg,
- &zero,
- sizeof(zero));
- if (retval < 0)
- return retval;
- }
- for (ii = 0; ii < rmi4_data->num_of_intr_regs; ii++) {
- if (intr_mask[ii] != 0x00) {
- f01_ctrl_reg = rmi4_data->f01_ctrl_base_addr + 1 + ii;
- if (set) {
- retval = f54->fn_ptr->write(rmi4_data,
- f01_ctrl_reg,
- &zero,
- sizeof(zero));
- if (retval < 0)
- return retval;
- } else {
- retval = f54->fn_ptr->write(rmi4_data,
- f01_ctrl_reg,
- &(intr_mask[ii]),
- sizeof(intr_mask[ii]));
- if (retval < 0)
- return retval;
- }
- }
- }
- f01_ctrl_reg = rmi4_data->f01_ctrl_base_addr + 1 + f54->intr_reg_num;
- if (set) {
- retval = f54->fn_ptr->write(rmi4_data,
- f01_ctrl_reg,
- &f54->intr_mask,
- 1);
- if (retval < 0)
- return retval;
- }
- return 0;
- }
- static int do_preparation(void)
- {
- int retval;
- unsigned char value;
- unsigned char command;
- unsigned char timeout_count;
- struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
- if (f54->query.touch_controller_family == 1) {
- value = 0;
- retval = f54->fn_ptr->write(rmi4_data,
- f54->control.reg_7->address,
- &value,
- sizeof(f54->control.reg_7->data));
- if (retval < 0) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Failed to disable CBC\n",
- __func__);
- return retval;
- }
- }
- #if 0 /* Below codes are just needed for 0D */
- if (f54->query.has_0d_acquisition_control) {
- value = 0;
- retval = f54->fn_ptr->write(rmi4_data,
- f54->control.reg_57->address,
- &value,
- sizeof(f54->control.reg_57->data));
- if (retval < 0) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Failed to disable 0D CBC\n",
- __func__);
- return retval;
- }
- }
- #endif
- if (f54->query.has_signal_clarity) {
- value = 1;
- retval = f54->fn_ptr->write(rmi4_data,
- f54->control.reg_41->address,
- &value,
- sizeof(f54->control.reg_41->data));
- if (retval < 0) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Failed to disable signal clarity\n",
- __func__);
- return retval;
- }
- }
- command = (unsigned char)COMMAND_FORCE_UPDATE;
- retval = f54->fn_ptr->write(rmi4_data,
- f54->command_base_addr,
- &command,
- sizeof(command));
- if (retval < 0) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Failed to write force update command\n",
- __func__);
- return retval;
- }
- timeout_count = 0;
- do {
- retval = f54->fn_ptr->read(rmi4_data,
- f54->command_base_addr,
- &value,
- sizeof(value));
- if (retval < 0) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Failed to read command register\n",
- __func__);
- return retval;
- }
- if (value == 0x00)
- break;
- msleep(100);
- timeout_count++;
- } while (timeout_count < FORCE_TIMEOUT_100MS);
- if (timeout_count == FORCE_TIMEOUT_100MS) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Timed out waiting for force update\n",
- __func__);
- return -ETIMEDOUT;
- }
- command = (unsigned char)COMMAND_FORCE_CAL;
- retval = f54->fn_ptr->write(rmi4_data,
- f54->command_base_addr,
- &command,
- sizeof(command));
- if (retval < 0) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Failed to write force cal command\n",
- __func__);
- return retval;
- }
- timeout_count = 0;
- do {
- retval = f54->fn_ptr->read(rmi4_data,
- f54->command_base_addr,
- &value,
- sizeof(value));
- if (retval < 0) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Failed to read command register\n",
- __func__);
- return retval;
- }
- if (value == 0x00)
- break;
- msleep(100);
- timeout_count++;
- } while (timeout_count < FORCE_TIMEOUT_100MS);
- if (timeout_count == FORCE_TIMEOUT_100MS) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Timed out waiting for force cal\n",
- __func__);
- return -ETIMEDOUT;
- }
- return 0;
- }
- #ifdef WATCHDOG_HRTIMER
- static void timeout_set_status(struct work_struct *work)
- {
- int retval;
- unsigned char command;
- struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
- dev_info(&rmi4_data->i2c_client->dev, "[synaptics] %s\n", __func__);
- mutex_lock(&f54->status_mutex);
- if (f54->status == STATUS_BUSY) {
- retval = f54->fn_ptr->read(rmi4_data,
- f54->command_base_addr,
- &command,
- sizeof(command));
- if (retval < 0) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Failed to read command register\n",
- __func__);
- f54->status = STATUS_ERROR;
- } else if (command & COMMAND_GET_REPORT) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Report type not supported by FW\n",
- __func__);
- f54->status = STATUS_ERROR;
- } else {
- queue_delayed_work(f54->status_workqueue,
- &f54->status_work,
- 0);
- mutex_unlock(&f54->status_mutex);
- return;
- }
- f54->report_type = INVALID_REPORT_TYPE;
- f54->report_size = 0;
- }
- mutex_unlock(&f54->status_mutex);
- /* read fail : need ic reset */
- if (f54->status == STATUS_ERROR) {
- if (rmi4_data->touch_stopped) {
- dev_err(&rmi4_data->i2c_client->dev, "%s: [ERROR] Touch is stopped\n",
- __func__);
- f54->status = STATUS_IDLE;
- return;
- }
- dev_err(&rmi4_data->i2c_client->dev, "%s: reset device\n",
- __func__);
- retval = rmi4_data->reset_device(rmi4_data);
- if (retval < 0) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Failed to issue reset command, error = %d\n",
- __func__, retval);
- }
- mutex_lock(&f54->status_mutex);
- f54->status = STATUS_IDLE;
- mutex_unlock(&f54->status_mutex);
- }
- return;
- }
- static enum hrtimer_restart get_report_timeout(struct hrtimer *timer)
- {
- schedule_work(&(f54->timeout_work));
- return HRTIMER_NORESTART;
- }
- #endif
- #ifdef RAW_HEX
- static void print_raw_hex_report(void)
- {
- unsigned int ii;
- pr_info("%s: Report data (raw hex)\n", __func__);
- switch (f54->report_type) {
- case F54_16BIT_IMAGE:
- case F54_RAW_16BIT_IMAGE:
- case F54_HIGH_RESISTANCE:
- case F54_TRUE_BASELINE:
- case F54_FULL_RAW_CAP_MIN_MAX:
- case F54_FULL_RAW_CAP:
- case F54_FULL_RAW_CAP_RX_COUPLING_COMP:
- case F54_SENSOR_SPEED:
- case F54_ADC_RANGE:
- for (ii = 0; ii < f54->report_size; ii += 2) {
- pr_info("%03d: 0x%02x%02x\n",
- ii / 2,
- f54->report_data[ii + 1],
- f54->report_data[ii]);
- }
- break;
- case F54_ABS_RAW_CAP:
- case F54_ABS_DELTA_CAP:
- for (ii = 0; ii < f54->report_size; ii += 4) {
- pr_info("%03d: 0x%02x%02x%02x%02x\n",
- ii / 4,
- f54->report_data[ii + 3],
- f54->report_data[ii + 2],
- f54->report_data[ii + 1],
- f54->report_data[ii]);
- }
- break;
- default:
- for (ii = 0; ii < f54->report_size; ii++)
- pr_info("%03d: 0x%02x\n", ii, f54->report_data[ii]);
- break;
- }
- return;
- }
- #endif
- #ifdef HUMAN_READABLE
- static void print_image_report(void)
- {
- unsigned int ii;
- unsigned int jj;
- short *report_data;
- switch (f54->report_type) {
- case F54_16BIT_IMAGE:
- case F54_RAW_16BIT_IMAGE:
- case F54_TRUE_BASELINE:
- case F54_FULL_RAW_CAP:
- case F54_FULL_RAW_CAP_RX_COUPLING_COMP:
- pr_info("%s: Report data (image)\n", __func__);
- report_data = (short *)f54->report_data;
- for (ii = 0; ii < f54->rmi4_data->num_of_tx; ii++) {
- for (jj = 0; jj < f54->rmi4_data->num_of_rx; jj++) {
- if (*report_data < -64)
- pr_cont(".");
- else if (*report_data < 0)
- pr_cont("-");
- else if (*report_data > 64)
- pr_cont("*");
- else if (*report_data > 0)
- pr_cont("+");
- else
- pr_cont("0");
- report_data++;
- }
- pr_info("");
- }
- pr_info("%s: End of report\n", __func__);
- break;
- default:
- pr_info("%s: Image not supported for report type %d\n",
- __func__, f54->report_type);
- }
- return;
- }
- #endif
- static void free_control_mem(void)
- {
- struct f54_control control = f54->control;
- kfree(control.reg_0);
- kfree(control.reg_1);
- kfree(control.reg_2);
- kfree(control.reg_3);
- kfree(control.reg_4__6);
- kfree(control.reg_7);
- kfree(control.reg_8__9);
- kfree(control.reg_10);
- kfree(control.reg_11);
- kfree(control.reg_12__13);
- kfree(control.reg_14);
- kfree(control.reg_15);
- kfree(control.reg_16);
- kfree(control.reg_17);
- kfree(control.reg_18);
- kfree(control.reg_19);
- kfree(control.reg_20);
- kfree(control.reg_21);
- kfree(control.reg_22__26);
- kfree(control.reg_27);
- kfree(control.reg_28);
- kfree(control.reg_29);
- kfree(control.reg_30);
- kfree(control.reg_31);
- kfree(control.reg_32__35);
- kfree(control.reg_36);
- kfree(control.reg_37);
- kfree(control.reg_38);
- kfree(control.reg_39);
- kfree(control.reg_40);
- kfree(control.reg_41);
- return;
- }
- static void remove_sysfs(void)
- {
- int reg_num;
- sysfs_remove_bin_file(f54->attr_dir, &dev_report_data);
- sysfs_remove_group(f54->attr_dir, &attr_group);
- for (reg_num = 0; reg_num < ARRAY_SIZE(attrs_ctrl_regs); reg_num++)
- sysfs_remove_group(f54->attr_dir, &attrs_ctrl_regs[reg_num]);
- kobject_put(f54->attr_dir);
- return;
- }
- #ifdef FACTORY_MODE
- static void set_default_result(struct factory_data *data)
- {
- char delim = ':';
- memset(data->cmd_buff, 0x00, sizeof(data->cmd_buff));
- memset(data->cmd_result, 0x00, sizeof(data->cmd_result));
- memcpy(data->cmd_result, data->cmd, strlen(data->cmd));
- strncat(data->cmd_result, &delim, 1);
- return;
- }
- static void set_cmd_result(struct factory_data *data, char *buf, int length)
- {
- strncat(data->cmd_result, buf, length);
- return;
- }
- static ssize_t cmd_store(struct device *dev, struct device_attribute *attr,
- const char *buf, size_t count)
- {
- unsigned char param_cnt = 0;
- char *start;
- char *end;
- char *pos;
- char delim = ',';
- char buffer[CMD_STR_LEN];
- bool cmd_found = false;
- int *param;
- int length;
- struct ft_cmd *ft_cmd_ptr;
- struct factory_data *data = f54->factory_data;
- struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
- #ifdef TSP_PATTERN_TRACKING_METHOD
- if (rmi4_data->pattern_data.is_working) {
- dev_err(&rmi4_data->i2c_client->dev, "%s: Skip cmd during pattern tracking workaround :%s\n",
- __func__, buf);
- return count;
- }
- #endif
- if (data->cmd_is_running == true) {
- dev_err(&rmi4_data->i2c_client->dev, "%s: Still servicing previous command. Skip cmd :%s\n",
- __func__, buf);
- return count;
- }
- if ((int)count >= CMD_STR_LEN) {
- dev_info(&rmi4_data->i2c_client->dev, "%s: cmd size overflow![%d]\n",
- __func__, (int)count);
- return count;
- }
- mutex_lock(&data->cmd_lock);
- data->cmd_is_running = true;
- mutex_unlock(&data->cmd_lock);
- data->cmd_state = CMD_STATUS_RUNNING;
- length = (int)count;
- if (*(buf + length - 1) == '\n')
- length--;
- memset(data->cmd, 0x00, sizeof(data->cmd));
- memcpy(data->cmd, buf, length);
- memset(data->cmd_param, 0, sizeof(data->cmd_param));
- memset(buffer, 0x00, sizeof(buffer));
- pos = strchr(buf, (int)delim);
- if (pos)
- memcpy(buffer, buf, pos - buf);
- else
- memcpy(buffer, buf, length);
- /* find command */
- list_for_each_entry(ft_cmd_ptr, &data->cmd_list_head, list) {
- if (!strcmp(buffer, ft_cmd_ptr->cmd_name)) {
- cmd_found = true;
- break;
- }
- }
- /* set not_support_cmd */
- if (!cmd_found) {
- list_for_each_entry(ft_cmd_ptr,
- &data->cmd_list_head, list) {
- if (!strcmp("not_support_cmd", ft_cmd_ptr->cmd_name))
- break;
- }
- }
- /* parsing parameters */
- if (cmd_found && pos) {
- pos++;
- start = pos;
- do {
- if ((*pos == delim) || (pos - buf == length)) {
- end = pos;
- memset(buffer, 0x00, sizeof(buffer));
- memcpy(buffer, start, end - start);
- *(buffer + strlen(buffer)) = '\0';
- param = data->cmd_param + param_cnt;
- if (kstrtoint(buffer, 10, param) < 0)
- break;
- param_cnt++;
- start = pos + 1;
- }
- pos++;
- } while ((pos - buf <= length) && (param_cnt < CMD_PARAM_NUM));
- }
- dev_info(&rmi4_data->i2c_client->dev, "%s: Command = %s\n",
- __func__, buf);
- ft_cmd_ptr->cmd_func();
- return count;
- }
- static ssize_t cmd_status_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- char buffer[16];
- struct factory_data *data = f54->factory_data;
- struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
- dev_info(&rmi4_data->i2c_client->dev, "%s: Command status = %d\n",
- __func__, data->cmd_state);
- switch (data->cmd_state) {
- case CMD_STATUS_WAITING:
- sprintf(buffer, "%s", tostring(WAITING));
- break;
- case CMD_STATUS_RUNNING:
- sprintf(buffer, "%s", tostring(RUNNING));
- break;
- case CMD_STATUS_OK:
- sprintf(buffer, "%s", tostring(OK));
- break;
- case CMD_STATUS_FAIL:
- sprintf(buffer, "%s", tostring(FAIL));
- break;
- case CMD_STATUS_NOT_APPLICABLE:
- sprintf(buffer, "%s", tostring(NOT_APPLICABLE));
- break;
- default:
- sprintf(buffer, "%s", tostring(NOT_APPLICABLE));
- break;
- }
- return snprintf(buf, PAGE_SIZE, "%s\n", buffer);
- }
- static ssize_t cmd_result_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct factory_data *data = f54->factory_data;
- struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
- dev_info(&rmi4_data->i2c_client->dev, "%s: Command result = %s\n",
- __func__, data->cmd_result);
- mutex_lock(&data->cmd_lock);
- data->cmd_is_running = false;
- mutex_unlock(&data->cmd_lock);
- data->cmd_state = CMD_STATUS_WAITING;
- return snprintf(buf, PAGE_SIZE, "%s\n", data->cmd_result);
- }
- static ssize_t cmd_list_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- int ii = 0;
- char buffer[CMD_RESULT_STR_LEN];
- char buffer_name[CMD_STR_LEN];
- snprintf(buffer, 30, "++factory command list++\n");
- while (strncmp(ft_cmds[ii].cmd_name, "not_support_cmd", 16) != 0) {
- snprintf(buffer_name, CMD_STR_LEN, "%s\n", ft_cmds[ii].cmd_name);
- strncat(buffer, buffer_name, strlen(buffer_name));
- ii++;
- }
- return snprintf(buf, PAGE_SIZE, "%s\n", buffer);
- }
- /* Caution : Below function run the force calibration for the mutual touch.
- * So it should be used for the specific case.
- */
- int synaptics_rmi4_force_calibration(void)
- {
- int retval;
- unsigned char command;
- struct synaptics_rmi4_data *rmi4_data;
- if (!f54)
- return -ENOMEM;
- if (f54->status == STATUS_BUSY)
- return -EBUSY;
- rmi4_data = f54->rmi4_data;
- command = (unsigned char)COMMAND_FORCE_CAL;
- retval = f54->fn_ptr->write(rmi4_data,
- f54->command_base_addr,
- &command,
- sizeof(command));
- dev_err(&rmi4_data->i2c_client->dev, "%s: Write force cal command %s\n",
- __func__, (retval < 0) ? "Fail" : "Sucess");
- return retval;
- }
- EXPORT_SYMBOL(synaptics_rmi4_force_calibration);
- /* TODO: Below function is added to check that firmware update is needed or not.
- * During development period, we need to support test firmware and various H/W
- * type such as A1/B0.... So Below conditions are very compex, maybe we need to
- * simplify this function not so far.
- * Synaptics's test firmware binary doesn't have Ic and firmware version.
- * in that case we skip update on booting time.
- * otherwise we forced run the update during UMS update..
- */
- extern int system_rev;
- static bool synaptics_skip_firmware_update(struct synaptics_rmi4_data *rmi4_data,
- const struct firmware *fw_entry)
- {
- /* Read revision and firmware info from binary */
- rmi4_data->ic_revision_of_bin = (int)fw_entry->data[IC_REVISION_BIN_OFFSET];
- rmi4_data->fw_version_of_bin = (int)fw_entry->data[FW_VERSION_BIN_OFFSET];
- dev_info(&rmi4_data->i2c_client->dev, "%s: [FW size. revision, version] [%d, 0x%02X/0x%02X(BIN/IC), 0x%02X/0x%02X(BIN/IC)]\n",
- __func__, fw_entry->size,
- rmi4_data->ic_revision_of_bin, rmi4_data->ic_revision_of_ic,
- rmi4_data->fw_version_of_bin, rmi4_data->fw_version_of_ic);
- dev_info(&rmi4_data->i2c_client->dev, "%s: [prog bit] [0x%02X]\n",
- __func__, rmi4_data->flash_prog_mode);
- if (system_rev < 6) {
- /* If old HW has FW above B019 or BF17, then It's not a proper FW. do FW update */
- if (((rmi4_data->ic_revision_of_ic == 0xB0) && (rmi4_data->fw_version_of_ic >= 0x19)) ||
- ((rmi4_data->ic_revision_of_ic == 0xBF) && (rmi4_data->fw_version_of_ic >= 0x17))) {
- dev_info(&rmi4_data->i2c_client->dev,
- "%s: new hw's FW is in old hw\n",
- __func__);
- return false;
- }
- }
- if (rmi4_data->flash_prog_mode) {
- dev_err(&rmi4_data->i2c_client->dev, "%s: Force firmware update : Flash prog bit is setted fw\n",
- __func__);
- return false;
- }
- if ((rmi4_data->ic_revision_of_bin == rmi4_data->ic_revision_of_ic)
- && (rmi4_data->fw_version_of_bin <= rmi4_data->fw_version_of_ic)
- && (rmi4_data->fw_version_of_ic < rmi4_data->fw_version_of_bin + 0x10)) {
- dev_info(&rmi4_data->i2c_client->dev, "%s: Do not need to update\n",
- __func__);
- return true;
- }
- return false;
- }
- int synaptics_rmi4_fw_update_on_probe(struct synaptics_rmi4_data *rmi4_data)
- {
- int retval;
- const struct firmware *fw_entry = NULL;
- unsigned char *fw_data = NULL;
- char fw_path[SYNAPTICS_MAX_FW_PATH];
- #ifdef CONFIG_SEC_FACTORY
- snprintf(fw_path, SYNAPTICS_MAX_FW_PATH,
- "%s", rmi4_data->fac_firmware_name);
- #else
- snprintf(fw_path, SYNAPTICS_MAX_FW_PATH,
- "%s", rmi4_data->firmware_name);
- #endif
- dev_info(&rmi4_data->i2c_client->dev, "%s: Load firmware : %s\n",
- __func__, fw_path);
- retval = request_firmware(&fw_entry, fw_path, &rmi4_data->i2c_client->dev);
- if (retval) {
- dev_err(&rmi4_data->i2c_client->dev, "%s: Firmware image %s not available\n",
- __func__, fw_path);
- goto done;
- }
- if (synaptics_skip_firmware_update(rmi4_data, fw_entry))
- goto done;
- fw_data = (unsigned char *)fw_entry->data;
- pr_info("%s: do fw update\n",__func__);
- retval = synaptics_fw_updater(fw_data);
- if (retval)
- dev_err(&rmi4_data->i2c_client->dev, "%s: failed update firmware\n",
- __func__);
- done:
- if (fw_entry)
- release_firmware(fw_entry);
- pr_info("synaptics %s:%d\n",__func__,__LINE__);
- return retval;
- }
- EXPORT_SYMBOL(synaptics_rmi4_fw_update_on_probe);
- static int synaptics_load_fw_from_kernel(struct synaptics_rmi4_data *rmi4_data, const char *fw_path)
- {
- int retval;
- const struct firmware *fw_entry = NULL;
- unsigned char *fw_data = NULL;
- if (!fw_path) {
- dev_err(&rmi4_data->i2c_client->dev, "%s: Firmware name is not defined\n",
- __func__);
- return -EINVAL;
- }
- dev_info(&rmi4_data->i2c_client->dev, "%s: Load firmware : %s\n",
- __func__, fw_path);
- retval = request_firmware(&fw_entry, fw_path,
- &rmi4_data->i2c_client->dev);
- if (retval) {
- dev_err(&rmi4_data->i2c_client->dev, "%s: Firmware image %s not available\n",
- __func__, fw_path);
- goto done;
- }
- fw_data = (unsigned char *)fw_entry->data;
- retval = synaptics_fw_updater(fw_data);
- if (retval)
- dev_err(&rmi4_data->i2c_client->dev, "%s: failed update firmware\n",
- __func__);
- done:
- if (fw_entry)
- release_firmware(fw_entry);
- return retval;
- }
- static int synaptics_load_fw_from_ums(struct synaptics_rmi4_data *rmi4_data)
- {
- struct file *fp;
- mm_segment_t old_fs;
- unsigned short fw_size, nread;
- int error = 0;
- old_fs = get_fs();
- set_fs(KERNEL_DS);
- fp = filp_open(SYNAPTICS_DEFAULT_UMS_FW, O_RDONLY, S_IRUSR);
- if (IS_ERR(fp)) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: failed to open %s.\n", __func__, SYNAPTICS_DEFAULT_UMS_FW);
- error = -ENOENT;
- goto open_err;
- }
- fw_size = fp->f_path.dentry->d_inode->i_size;
- if (0 < fw_size) {
- unsigned char *fw_data;
- fw_data = kzalloc(fw_size, GFP_KERNEL);
- nread = vfs_read(fp, (char __user *)fw_data,
- fw_size, &fp->f_pos);
- dev_info(&rmi4_data->i2c_client->dev,
- "%s: start, file path %s, size %u Bytes\n", __func__,
- SYNAPTICS_DEFAULT_UMS_FW, fw_size);
- if (nread != fw_size) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: failed to read firmware file, nread %u Bytes\n",
- __func__,
- nread);
- error = -EIO;
- }
- else
- error = synaptics_fw_updater(fw_data);
- if (error < 0)
- dev_err(&rmi4_data->i2c_client->dev, "%s: failed update firmware\n",
- __func__);
- kfree(fw_data);
- }
- filp_close(fp, current->files);
- open_err:
- set_fs(old_fs);
- return error;
- }
- static int synaptics_rmi4_fw_update_on_hidden_menu(struct synaptics_rmi4_data *rmi4_data,
- int update_type)
- {
- int retval = 0;
- /* Factory cmd for firmware update
- * argument represent what is source of firmware like below.
- *
- * 0 : Getting firmware which is for user.
- * 1 : Getting firmware from sd card.
- * 2 : Getting firmware which is for factory test.
- */
- switch (update_type) {
- case 0:
- retval = synaptics_load_fw_from_kernel(rmi4_data, rmi4_data->firmware_name);
- break;
- case 1:
- retval = synaptics_load_fw_from_ums(rmi4_data);
- break;
- case 2:
- retval = synaptics_load_fw_from_kernel(rmi4_data, rmi4_data->fac_firmware_name);
- break;
- default:
- dev_err(&rmi4_data->i2c_client->dev, "%s: Not support command[%d]\n",
- __func__, update_type);
- break;
- }
- return retval;
- }
- static void fw_update(void)
- {
- struct factory_data *data = f54->factory_data;
- struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
- int retval = 0;
- set_default_result(data);
- retval = synaptics_rmi4_fw_update_on_hidden_menu(rmi4_data,
- data->cmd_param[0]);
- msleep(1000);
- if (retval < 0) {
- sprintf(data->cmd_buff, "%s", tostring(NA));
- set_cmd_result(data, data->cmd_buff, strlen(data->cmd_buff));
- data->cmd_state = CMD_STATUS_FAIL;
- dev_err(&rmi4_data->i2c_client->dev, "%s: failed [%d]\n",
- __func__, retval);
- } else {
- sprintf(data->cmd_buff, "%s", tostring(OK));
- set_cmd_result(data, data->cmd_buff, strlen(data->cmd_buff));
- data->cmd_state = CMD_STATUS_OK;
- dev_info(&rmi4_data->i2c_client->dev, "%s: success [%d]\n",
- __func__, retval);
- }
- return;
- }
- static void get_fw_ver_bin(void)
- {
- struct factory_data *data = f54->factory_data;
- struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
- set_default_result(data);
- sprintf(data->cmd_buff, "SY%04X%02X",
- rmi4_data->ic_revision_of_bin,
- rmi4_data->fw_version_of_bin);
- set_cmd_result(data, data->cmd_buff, strlen(data->cmd_buff));
- data->cmd_state = CMD_STATUS_OK;
- return;
- }
- static void get_fw_ver_ic(void)
- {
- struct factory_data *data = f54->factory_data;
- struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
- set_default_result(data);
- sprintf(data->cmd_buff, "SY%04X%02X",
- rmi4_data->ic_revision_of_ic,
- rmi4_data->fw_version_of_ic);
- set_cmd_result(data, data->cmd_buff, strlen(data->cmd_buff));
- data->cmd_state = CMD_STATUS_OK;
- return;
- }
- static void get_fac_fw_ver_bin(void)
- {
- struct factory_data *data = f54->factory_data;
- struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
- int retval;
- const struct firmware *fw_entry = NULL;
- set_default_result(data);
- retval = request_firmware(&fw_entry, rmi4_data->fac_firmware_name,
- &rmi4_data->i2c_client->dev);
- if (retval < 0) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: factory firmware request failed\n",
- __func__);
- snprintf(data->cmd_buff, sizeof(data->cmd_buff), "NG");
- set_cmd_result(data, data->cmd_buff, strlen(data->cmd_buff));
- data->cmd_state = CMD_STATUS_FAIL;
- } else {
- sprintf(data->cmd_buff, "SY%02X%02X%02X",
- (int)fw_entry->data[DATE_OF_FIRMWARE_BIN_OFFSET],
- (int)fw_entry->data[IC_REVISION_BIN_OFFSET],
- (int)fw_entry->data[FW_VERSION_BIN_OFFSET]);
- set_cmd_result(data, data->cmd_buff, strlen(data->cmd_buff));
- data->cmd_state = CMD_STATUS_OK;
- }
- release_firmware(fw_entry);
- return;
- }
- static void get_config_ver(void)
- {
- struct factory_data *data = f54->factory_data;
- struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
- set_default_result(data);
- sprintf(data->cmd_buff, "%s_SY_%02d%02d",
- SYNAPTICS_DEVICE_NAME, rmi4_data->fw_release_date_of_ic >> 8,
- rmi4_data->fw_release_date_of_ic & 0x00FF);
- set_cmd_result(data, data->cmd_buff, strlen(data->cmd_buff));
- data->cmd_state = CMD_STATUS_OK;
- return;
- }
- static void get_threshold(void)
- {
- unsigned char SaturationCap_LSB;
- unsigned char SaturationCap_MSB;
- unsigned char FingerAmplitudeThreshold;
- unsigned int SaturationCap;
- unsigned int threshold_integer;
- unsigned int threshold_fraction;
- struct factory_data *data = f54->factory_data;
- struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
- f54->fn_ptr->read(rmi4_data,
- F12_CTRL15_ADDR,
- &FingerAmplitudeThreshold,
- sizeof(FingerAmplitudeThreshold));
- f54->fn_ptr->read(rmi4_data,
- f54->control.reg_2->address,
- &SaturationCap_LSB,
- sizeof(SaturationCap_LSB));
- f54->fn_ptr->read(rmi4_data,
- f54->control.reg_2->address + 1,
- &SaturationCap_MSB,
- sizeof(SaturationCap_MSB));
- SaturationCap = (SaturationCap_LSB & 0xFF) | ((SaturationCap_MSB & 0xFF) <<8);
- threshold_integer = (FingerAmplitudeThreshold * SaturationCap)/256;
- threshold_fraction = ((FingerAmplitudeThreshold * SaturationCap * 1000)/256)%1000;
- dev_info(&rmi4_data->i2c_client->dev,
- "%s: FingerAmp : %d, Satruration cap : %d\n",
- __func__, FingerAmplitudeThreshold, SaturationCap);
- set_default_result(data);
- sprintf(data->cmd_buff, "%u.%u",
- threshold_integer, threshold_fraction);
- set_cmd_result(data, data->cmd_buff, strlen(data->cmd_buff));
- data->cmd_state = CMD_STATUS_OK;
- return;
- }
- static void module_off_master(void)
- {
- struct factory_data *data = f54->factory_data;
- struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
- set_default_result(data);
- mutex_lock(&rmi4_data->input_dev->mutex);
- rmi4_data->stop_device(rmi4_data);
- mutex_unlock(&rmi4_data->input_dev->mutex);
- sprintf(data->cmd_buff, "%s", tostring(OK));
- data->cmd_state = CMD_STATUS_OK;
- set_cmd_result(data, data->cmd_buff, strlen(data->cmd_buff));
- }
- static void module_on_master(void)
- {
- struct factory_data *data = f54->factory_data;
- struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
- int retval;
- set_default_result(data);
- mutex_lock(&rmi4_data->input_dev->mutex);
- retval = rmi4_data->start_device(rmi4_data);
- if (retval < 0)
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Failed to start device\n", __func__);
- mutex_unlock(&rmi4_data->input_dev->mutex);
- sprintf(data->cmd_buff, "%s", tostring(OK));
- data->cmd_state = CMD_STATUS_OK;
- set_cmd_result(data, data->cmd_buff, strlen(data->cmd_buff));
- }
- static void get_chip_vendor(void)
- {
- struct factory_data *data = f54->factory_data;
- set_default_result(data);
- sprintf(data->cmd_buff, "%s", tostring(SYNAPTICS));
- data->cmd_state = CMD_STATUS_OK;
- set_cmd_result(data, data->cmd_buff, strlen(data->cmd_buff));
- }
- static void get_chip_name(void)
- {
- struct factory_data *data = f54->factory_data;
- set_default_result(data);
- sprintf(data->cmd_buff, "%s", tostring(S5000));
- data->cmd_state = CMD_STATUS_OK;
- set_cmd_result(data, data->cmd_buff, strlen(data->cmd_buff));
- }
- static void get_x_num(void)
- {
- struct factory_data *data = f54->factory_data;
- struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
- set_default_result(data);
- sprintf(data->cmd_buff, "%d", rmi4_data->num_of_tx);
- set_cmd_result(data, data->cmd_buff, strlen(data->cmd_buff));
- data->cmd_state = CMD_STATUS_OK;
- return;
- }
- static void get_y_num(void)
- {
- struct factory_data *data = f54->factory_data;
- struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
- set_default_result(data);
- sprintf(data->cmd_buff, "%d", rmi4_data->num_of_rx);
- set_cmd_result(data, data->cmd_buff, strlen(data->cmd_buff));
- data->cmd_state = CMD_STATUS_OK;
- return;
- }
- static int check_rx_tx_num(void)
- {
- struct factory_data *data = f54->factory_data;
- struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
- int node;
- dev_info(&rmi4_data->i2c_client->dev, "%s: param[0] = %d, param[1] = %d\n",
- __func__, data->cmd_param[0], data->cmd_param[1]);
- if (data->cmd_param[0] < 0 ||
- data->cmd_param[0] >= rmi4_data->num_of_tx ||
- data->cmd_param[1] < 0 ||
- data->cmd_param[1] >= rmi4_data->num_of_rx) {
- sprintf(data->cmd_buff, "%s", tostring(NA));
- set_cmd_result(data, data->cmd_buff, strlen(data->cmd_buff));
- data->cmd_state = CMD_STATUS_FAIL;
- dev_info(&rmi4_data->i2c_client->dev, "%s: parameter error: %u,%u\n",
- __func__, data->cmd_param[0], data->cmd_param[1]);
- node = -1;
- } else {
- node = data->cmd_param[0] * rmi4_data->num_of_tx +
- data->cmd_param[1];
- dev_info(&rmi4_data->i2c_client->dev, "%s: node = %d\n",
- __func__, node);
- }
- return node;
- }
- static void get_rawcap(void)
- {
- int node;
- short report_data;
- struct factory_data *data = f54->factory_data;
- set_default_result(data);
- node = check_rx_tx_num();
- if (node < 0) {
- data->cmd_state = CMD_STATUS_FAIL;
- return;
- } else {
- report_data = f54->factory_data->rawcap_data[node];
- sprintf(data->cmd_buff, "%d", report_data);
- set_cmd_result(data, data->cmd_buff, strlen(data->cmd_buff));
- data->cmd_state = CMD_STATUS_OK;
- }
- return;
- }
- static void run_rawcap_read(void)
- {
- int retval;
- int kk = 0;
- unsigned char ii;
- unsigned char jj;
- unsigned char num_of_tx;
- unsigned char num_of_rx;
- short *report_data;
- short max_value;
- short min_value;
- short cur_value;
- struct factory_data *data = f54->factory_data;
- struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
- unsigned char command = 0x01;
- set_default_result(data);
- if (f54->rmi4_data->ic_revision_of_ic != 0xBF) {
- dev_info(&f54->rmi4_data->i2c_client->dev,
- "%s: this is not Factory FW.\n", __func__);
- sprintf(data->cmd_buff, "%s", "Not Factory Firmware");
- set_cmd_result(data, data->cmd_buff, strlen(data->cmd_buff));
- data->cmd_state = CMD_STATUS_NOT_APPLICABLE;
- return;
- }
- if (rmi4_data->touch_stopped) {
- dev_err(&rmi4_data->i2c_client->dev, "%s: [ERROR] Touch is stopped\n",
- __func__);
- sprintf(data->cmd_buff, "%s", "TSP turned off");
- set_cmd_result(data, data->cmd_buff, strlen(data->cmd_buff));
- data->cmd_state = CMD_STATUS_NOT_APPLICABLE;
- return;
- }
- retval = do_preparation();
- if (retval < 0) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Failed to do preparation\n",
- __func__);
- sprintf(data->cmd_buff, "%s", "Error preparation");
- set_cmd_result(data, data->cmd_buff, strlen(data->cmd_buff));
- data->cmd_state = CMD_STATUS_NOT_APPLICABLE;
- return;
- }
- if (!synaptics_rmi4_f54_get_report_type(CMD_REPORT_TYPE_RAWCAP)) {
- data->cmd_state = CMD_STATUS_FAIL;
- goto exit;
- }
- report_data = f54->factory_data->rawcap_data;
- memcpy(report_data, f54->report_data, f54->report_size);
- num_of_tx = rmi4_data->num_of_tx;
- num_of_rx = rmi4_data->num_of_rx;
- max_value = min_value = report_data[0];
- for (ii = 0; ii < num_of_tx; ii++) {
- for (jj = 0; jj < num_of_rx; jj++) {
- cur_value = *report_data;
- max_value = max(max_value, cur_value);
- min_value = min(min_value, cur_value);
- report_data++;
- if (cur_value > TSP_RAWCAP_MAX || cur_value < TSP_RAWCAP_MIN)
- dev_info(&rmi4_data->i2c_client->dev,
- "tx = %02d, rx = %02d, data[%d] = %d\n",
- ii, jj, kk, cur_value);
- kk++;
- }
- }
- sprintf(data->cmd_buff, "%d,%d", min_value, max_value);
- set_cmd_result(data, data->cmd_buff, strlen(data->cmd_buff));
- data->cmd_state = CMD_STATUS_OK;
- exit:
- /* soft reset */
- retval = f54->fn_ptr->write(rmi4_data,
- rmi4_data->f01_cmd_base_addr,
- &command,
- sizeof(command));
- if (retval < 0) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Failed to issue reset command, error = %d\n",
- __func__, retval);
- }
- return;
- }
- static void get_delta(void)
- {
- int node;
- short report_data;
- struct factory_data *data = f54->factory_data;
- set_default_result(data);
- node = check_rx_tx_num();
- if (node < 0) {
- data->cmd_state = CMD_STATUS_FAIL;
- return;
- } else {
- report_data = f54->factory_data->delta_data[node];
- sprintf(data->cmd_buff, "%d", report_data);
- set_cmd_result(data, data->cmd_buff, strlen(data->cmd_buff));
- data->cmd_state = CMD_STATUS_OK;
- }
- }
- static void run_delta_read(void)
- {
- struct factory_data *data = f54->factory_data;
- struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
- short *report_data;
- short cur_value;
- unsigned char ii;
- unsigned char jj;
- unsigned char num_of_tx;
- unsigned char num_of_rx;
- int kk = 0;
- set_default_result(data);
- if (f54->rmi4_data->ic_revision_of_ic != 0xBF) {
- dev_info(&f54->rmi4_data->i2c_client->dev,
- "%s: this is not Factory FW.\n", __func__);
- sprintf(data->cmd_buff, "%s", "Not Factory Firmware");
- set_cmd_result(data, data->cmd_buff, strlen(data->cmd_buff));
- data->cmd_state = CMD_STATUS_NOT_APPLICABLE;
- return;
- }
- if (rmi4_data->touch_stopped) {
- dev_err(&rmi4_data->i2c_client->dev, "%s: [ERROR] Touch is stopped\n",
- __func__);
- sprintf(data->cmd_buff, "%s", "TSP turned off");
- set_cmd_result(data, data->cmd_buff, strlen(data->cmd_buff));
- data->cmd_state = CMD_STATUS_NOT_APPLICABLE;
- return;
- }
- if (!synaptics_rmi4_f54_get_report_type(CMD_REPORT_TYPE_DELTA)) {
- data->cmd_state = CMD_STATUS_FAIL;
- return;
- }
- report_data = f54->factory_data->delta_data;
- memcpy(report_data, f54->report_data, f54->report_size);
- num_of_tx = rmi4_data->num_of_tx;
- num_of_rx = rmi4_data->num_of_rx;
- for (ii = 0; ii < num_of_tx; ii++) {
- for (jj = 0; jj < num_of_rx; jj++) {
- cur_value = *report_data;
- report_data++;
- if (cur_value > TSP_DELTA_MAX || cur_value < TSP_DELTA_MIN)
- dev_info(&rmi4_data->i2c_client->dev,
- "tx = %02d, rx = %02d, data[%d] = %d\n",
- ii, jj, kk, cur_value);
- kk++;
- }
- }
- snprintf(data->cmd_buff, sizeof(data->cmd_buff), "OK");
- set_cmd_result(data, data->cmd_buff, strlen(data->cmd_buff));
- data->cmd_state = CMD_STATUS_OK;
- return;
- }
- static void run_abscap_read(void)
- {
- struct factory_data *data = f54->factory_data;
- struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
- unsigned short *report_data;
- char temp[CMD_STR_LEN];
- char temp2[CMD_RESULT_STR_LEN];
- unsigned char ii;
- unsigned short num_of_tx;
- unsigned short num_of_rx;
- set_default_result(data);
- if (f54->rmi4_data->ic_revision_of_ic != 0xBF) {
- dev_info(&f54->rmi4_data->i2c_client->dev,
- "%s: this is not Factory FW.\n", __func__);
- sprintf(data->cmd_buff, "%s", "Not Factory Firmware");
- set_cmd_result(data, data->cmd_buff, strlen(data->cmd_buff));
- data->cmd_state = CMD_STATUS_NOT_APPLICABLE;
- return;
- }
- if (rmi4_data->touch_stopped) {
- dev_err(&rmi4_data->i2c_client->dev, "%s: [ERROR] Touch is stopped\n",
- __func__);
- sprintf(data->cmd_buff, "%s", "TSP turned off");
- set_cmd_result(data, data->cmd_buff, strlen(data->cmd_buff));
- data->cmd_state = CMD_STATUS_NOT_APPLICABLE;
- return;
- }
- if (!synaptics_rmi4_f54_get_report_type(F54_ABS_RAW_CAP)) {
- data->cmd_state = CMD_STATUS_FAIL;
- return;
- }
- report_data = f54->factory_data->abscap_data;
- memcpy(report_data, f54->report_data, f54->report_size);
- memset(temp, 0, CMD_STR_LEN);
- memset(temp2, 0, CMD_RESULT_STR_LEN);
- num_of_tx = rmi4_data->num_of_tx;
- num_of_rx = rmi4_data->num_of_rx;
- for (ii = 0; ii < num_of_rx + num_of_tx; ii++) {
- *report_data &= 0x0FFFF;
- dev_info(&rmi4_data->i2c_client->dev,
- "%s: %s [%d] = %d\n", __func__,
- ii >= num_of_rx ? "Tx" : "Rx",
- ii < num_of_rx ? ii : ii - num_of_rx,
- *report_data);
- sprintf(temp, "%d,", *report_data);
- strncat(temp2, temp, 9);
- report_data += 2;
- }
- sprintf(data->cmd_buff, "%s", temp2);
- set_cmd_result(data, data->cmd_buff, strlen(data->cmd_buff));
- data->cmd_state = CMD_STATUS_OK;
- return;
- }
- static void run_absdelta_read(void)
- {
- struct factory_data *data = f54->factory_data;
- struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
- short *report_data;
- char temp[CMD_STR_LEN];
- char temp2[CMD_RESULT_STR_LEN];
- unsigned char ii;
- unsigned short num_of_tx;
- unsigned short num_of_rx;
- set_default_result(data);
- if (f54->rmi4_data->ic_revision_of_ic != 0xBF) {
- dev_info(&f54->rmi4_data->i2c_client->dev,
- "%s: this is not Factory FW.\n", __func__);
- sprintf(data->cmd_buff, "%s", "Not Factory Firmware");
- set_cmd_result(data, data->cmd_buff, strlen(data->cmd_buff));
- data->cmd_state = CMD_STATUS_NOT_APPLICABLE;
- return;
- }
- if (rmi4_data->touch_stopped) {
- dev_err(&rmi4_data->i2c_client->dev, "%s: [ERROR] Touch is stopped\n",
- __func__);
- sprintf(data->cmd_buff, "%s", "TSP turned off");
- set_cmd_result(data, data->cmd_buff, strlen(data->cmd_buff));
- data->cmd_state = CMD_STATUS_NOT_APPLICABLE;
- return;
- }
- if (!synaptics_rmi4_f54_get_report_type(F54_ABS_DELTA_CAP)) {
- data->cmd_state = CMD_STATUS_FAIL;
- return;
- }
- report_data = f54->factory_data->absdelta_data;
- memcpy(report_data, f54->report_data, f54->report_size);
- memset(temp, 0, CMD_STR_LEN);
- memset(temp2, 0, CMD_RESULT_STR_LEN);
- num_of_tx = rmi4_data->num_of_tx;
- num_of_rx = rmi4_data->num_of_rx;
- for (ii = 0; ii < num_of_rx + num_of_tx; ii++) {
- dev_info(&rmi4_data->i2c_client->dev,
- "%s: %s [%d] = %d\n", __func__,
- ii >= num_of_rx ? "Tx" : "Rx",
- ii < num_of_rx ? ii : ii - num_of_rx,
- *report_data);
- sprintf(temp, "%d,", *report_data);
- strncat(temp2, temp, 5);
- report_data += 2;
- }
- sprintf(data->cmd_buff, "%s", temp2);
- set_cmd_result(data, data->cmd_buff, strlen(data->cmd_buff));
- data->cmd_state = CMD_STATUS_OK;
- return;
- }
- static void run_trx_short_test(void)
- {
- struct factory_data *data = f54->factory_data;
- struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
- short *report_data;
- unsigned char ii;
- int retval = 0;
- unsigned char command = 0x01;
- set_default_result(data);
- if (f54->rmi4_data->ic_revision_of_ic != 0xBF) {
- dev_info(&f54->rmi4_data->i2c_client->dev,
- "%s: this is not Factory FW.\n", __func__);
- sprintf(data->cmd_buff, "%s", "Not Factory Firmware");
- set_cmd_result(data, data->cmd_buff, strlen(data->cmd_buff));
- data->cmd_state = CMD_STATUS_NOT_APPLICABLE;
- return;
- }
- if (rmi4_data->touch_stopped) {
- dev_err(&rmi4_data->i2c_client->dev, "%s: [ERROR] Touch is stopped\n",
- __func__);
- sprintf(data->cmd_buff, "%s", "TSP turned off");
- set_cmd_result(data, data->cmd_buff, strlen(data->cmd_buff));
- data->cmd_state = CMD_STATUS_NOT_APPLICABLE;
- return;
- }
- disable_irq(rmi4_data->i2c_client->irq);
- if (!synaptics_rmi4_f54_get_report_type(F54_TREX_SHORTS)) {
- data->cmd_state = CMD_STATUS_FAIL;
- goto exit;
- }
- report_data = f54->factory_data->trx_short;
- memcpy(report_data, f54->report_data, f54->report_size);
- for (ii = 0; ii < f54->report_size; ii++) {
- dev_info(&rmi4_data->i2c_client->dev,
- "%s: [%d]: [%x][%x][%x][%x][%x][%x][%x][%x]\n",
- __func__, ii, *report_data & 0x1, (*report_data & 0x2) >> 1,
- (*report_data & 0x4) >> 2, (*report_data & 0x8) >> 3,
- (*report_data & 0x10) >> 4, (*report_data & 0x20) >> 5,
- (*report_data & 0x40) >> 6, (*report_data & 0x80) >> 7);
- if (*report_data > 0)
- retval++;
- report_data++;
- }
- if (retval > 0)
- sprintf(data->cmd_buff, "FAIL");
- else
- sprintf(data->cmd_buff, "OK");
- set_cmd_result(data, data->cmd_buff, strlen(data->cmd_buff));
- data->cmd_state = CMD_STATUS_OK;
- exit:
- enable_irq(rmi4_data->i2c_client->irq);
- /* soft reset */
- retval = f54->fn_ptr->write(rmi4_data,
- rmi4_data->f01_cmd_base_addr,
- &command,
- sizeof(command));
- if (retval < 0) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Failed to issue reset command, error = %d\n",
- __func__, retval);
- }
- return;
- }
- static void hover_enable(void)
- {
- struct factory_data *data = f54->factory_data;
- struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
- set_default_result(data);
- if (data->cmd_param[0] < 0 || data->cmd_param[0] > 1) {
- snprintf(data->cmd_buff, sizeof(data->cmd_buff), "NG");
- data->cmd_state = CMD_STATUS_FAIL;
- } else {
- int retval, enables;
- enables = data->cmd_param[0];
- rmi4_data->hover_status_in_normal_mode = data->cmd_param[0];
- rmi4_data->hover_called = true;
- rmi4_data->hover_ic = rmi4_data->flip_status;
- retval = synaptics_rmi4_proximity_enables(enables);
- if (retval < 0) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s failed, retval = %d\n",
- __func__, retval);
- snprintf(data->cmd_buff, sizeof(data->cmd_buff), "NG");
- data->cmd_state = CMD_STATUS_FAIL;
- } else {
- snprintf(data->cmd_buff, sizeof(data->cmd_buff), "OK");
- data->cmd_state = CMD_STATUS_OK;
- }
- snprintf(data->cmd_buff, sizeof(data->cmd_buff), "OK");
- data->cmd_state = CMD_STATUS_OK;
- }
- set_cmd_result(data, data->cmd_buff, strlen(data->cmd_buff));
- mutex_lock(&data->cmd_lock);
- data->cmd_is_running = false;
- mutex_unlock(&data->cmd_lock);
- data->cmd_state = CMD_STATUS_WAITING;
- return;
- }
- static void hover_no_sleep_enable(void)
- {
- struct factory_data *data = f54->factory_data;
- struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
- set_default_result(data);
- if (data->cmd_param[0] < 0 || data->cmd_param[0] > 1) {
- snprintf(data->cmd_buff, sizeof(data->cmd_buff), "NG");
- data->cmd_state = CMD_STATUS_FAIL;
- } else {
- int retval;
- if (data->cmd_param[0])
- retval = synaptics_proximity_no_sleep_set(true);
- else
- retval = synaptics_proximity_no_sleep_set(false);
- if (retval < 0) {
- dev_err(&rmi4_data->i2c_client->dev, "%s failed, retval = %d\n",
- __func__, retval);
- snprintf(data->cmd_buff, sizeof(data->cmd_buff), "NG");
- data->cmd_state = CMD_STATUS_FAIL;
- } else {
- snprintf(data->cmd_buff, sizeof(data->cmd_buff), "OK");
- data->cmd_state = CMD_STATUS_OK;
- }
- }
- set_cmd_result(data, data->cmd_buff, strlen(data->cmd_buff));
- return;
- }
- #ifdef CONFIG_GLOVE_TOUCH
- #define GLOVE_MODE_EN (1 << 0)
- #define CLEAR_COVER_EN (1 << 1)
- #define FAST_GLOVE_MODE_EN (1 << 2)
- static void glove_mode(void)
- {
- struct factory_data *data = f54->factory_data;
- struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
- set_default_result(data);
- if (rmi4_data->glove_mode_enables & CLEAR_COVER_EN) {
- snprintf(data->cmd_buff, sizeof(data->cmd_buff), "OK");
- data->cmd_state = CMD_STATUS_OK;
- dev_info(&rmi4_data->i2c_client->dev,
- "%s Skip glove mode set (cover bit enabled)\n",
- __func__);
- goto skip_glove_mode_set;
- }
- if (data->cmd_param[0] < 0 || data->cmd_param[0] > 1) {
- snprintf(data->cmd_buff, sizeof(data->cmd_buff), "NG");
- data->cmd_state = CMD_STATUS_FAIL;
- } else {
- int retval;
- if (data->cmd_param[0])
- rmi4_data->glove_mode_enables |= GLOVE_MODE_EN;
- else
- rmi4_data->glove_mode_enables &= ~(GLOVE_MODE_EN);
- retval = synaptics_rmi4_glove_mode_enables(rmi4_data);
- if (retval < 0) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s failed, retval = %d\n",
- __func__, retval);
- snprintf(data->cmd_buff, sizeof(data->cmd_buff), "NG");
- data->cmd_state = CMD_STATUS_FAIL;
- } else {
- snprintf(data->cmd_buff, sizeof(data->cmd_buff), "OK");
- data->cmd_state = CMD_STATUS_OK;
- }
- }
- skip_glove_mode_set:
- set_cmd_result(data, data->cmd_buff, strlen(data->cmd_buff));
- mutex_lock(&data->cmd_lock);
- data->cmd_is_running = false;
- mutex_unlock(&data->cmd_lock);
- data->cmd_state = CMD_STATUS_WAITING;
- return;
- }
- static void fast_glove_mode(void)
- {
- struct factory_data *data = f54->factory_data;
- struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
- set_default_result(data);
- if (data->cmd_param[0] < 0 || data->cmd_param[0] > 1) {
- snprintf(data->cmd_buff, sizeof(data->cmd_buff), "NG");
- data->cmd_state = CMD_STATUS_FAIL;
- } else {
- int retval;
- if (data->cmd_param[0]) {
- rmi4_data->glove_mode_enables |= FAST_GLOVE_MODE_EN | GLOVE_MODE_EN;
- rmi4_data->fast_glove_state = true;
- }
- else {
- rmi4_data->glove_mode_enables &= ~(FAST_GLOVE_MODE_EN);
- rmi4_data->fast_glove_state = false;
- }
- retval = synaptics_rmi4_glove_mode_enables(rmi4_data);
- if (retval < 0) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s failed, retval = %d\n",
- __func__, retval);
- snprintf(data->cmd_buff, sizeof(data->cmd_buff), "NG");
- data->cmd_state = CMD_STATUS_FAIL;
- } else {
- snprintf(data->cmd_buff, sizeof(data->cmd_buff), "OK");
- data->cmd_state = CMD_STATUS_OK;
- }
- }
- set_cmd_result(data, data->cmd_buff, strlen(data->cmd_buff));
- mutex_lock(&data->cmd_lock);
- data->cmd_is_running = false;
- mutex_unlock(&data->cmd_lock);
- data->cmd_state = CMD_STATUS_WAITING;
- return;
- }
- static void clear_cover_mode(void)
- {
- struct factory_data *data = f54->factory_data;
- struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
- set_default_result(data);
- if (data->cmd_param[0] < 0 || data->cmd_param[0] > 3) {
- snprintf(data->cmd_buff, sizeof(data->cmd_buff), "NG");
- data->cmd_state = CMD_STATUS_FAIL;
- } else {
- int retval;
- rmi4_data->glove_mode_enables = data->cmd_param[0];
- if (data->cmd_param[0] && rmi4_data->fast_glove_state)
- rmi4_data->glove_mode_enables |= FAST_GLOVE_MODE_EN;
- retval = synaptics_rmi4_glove_mode_enables(rmi4_data);
- if (retval < 0) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s failed, retval = %d\n",
- __func__, retval);
- snprintf(data->cmd_buff, sizeof(data->cmd_buff), "NG");
- data->cmd_state = CMD_STATUS_FAIL;
- } else {
- snprintf(data->cmd_buff, sizeof(data->cmd_buff), "OK");
- data->cmd_state = CMD_STATUS_OK;
- }
- /* Sync user setting value when wakeup with flip cover opened */
- if ((0x02 == rmi4_data->glove_mode_enables) ||
- (0x06 == rmi4_data->glove_mode_enables)) {
- rmi4_data->glove_mode_enables &= ~(CLEAR_COVER_EN);
- if (rmi4_data->fast_glove_state)
- rmi4_data->glove_mode_enables |= GLOVE_MODE_EN;
- }
- }
- set_cmd_result(data, data->cmd_buff, strlen(data->cmd_buff));
- mutex_lock(&data->cmd_lock);
- data->cmd_is_running = false;
- mutex_unlock(&data->cmd_lock);
- data->cmd_state = CMD_STATUS_WAITING;
- return;
- }
- static void get_glove_sensitivity(void)
- {
- struct factory_data *data = f54->factory_data;
- struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
- set_default_result(data);
- dev_info(&rmi4_data->i2c_client->dev,
- "%s : %x\n", __func__, rmi4_data->gloved_sensitivity & 0x0F);
- sprintf(data->cmd_buff, "%x", rmi4_data->gloved_sensitivity & 0x0F);
- set_cmd_result(data, data->cmd_buff, strlen(data->cmd_buff));
- data->cmd_state = CMD_STATUS_OK;
- return;
- }
- #endif
- #ifdef TSP_BOOSTER
- static void boost_level(void)
- {
- struct factory_data *data = f54->factory_data;
- struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
- int retval;
- dev_info(&rmi4_data->i2c_client->dev, "%s\n", __func__);
- set_default_result(data);
- rmi4_data->dvfs_boost_mode = data->cmd_param[0];
- dev_info(&rmi4_data->i2c_client->dev,
- "%s: dvfs_boost_mode = %d\n",
- __func__, rmi4_data->dvfs_boost_mode);
- snprintf(data->cmd_buff, sizeof(data->cmd_buff), "OK");
- data->cmd_state = CMD_STATUS_OK;
- if (rmi4_data->dvfs_boost_mode == DVFS_STAGE_NONE) {
- retval = set_freq_limit(DVFS_TOUCH_ID, -1);
- if (retval < 0) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: booster stop failed(%d).\n",
- __func__, retval);
- snprintf(data->cmd_buff, sizeof(data->cmd_buff), "NG");
- data->cmd_state = CMD_STATUS_FAIL;
- rmi4_data->dvfs_lock_status = false;
- }
- }
- set_cmd_result(data, data->cmd_buff, strlen(data->cmd_buff));
- mutex_lock(&data->cmd_lock);
- data->cmd_is_running = false;
- mutex_unlock(&data->cmd_lock);
- data->cmd_state = CMD_STATUS_WAITING;
- return;
- }
- #endif
- static void switch_sel(void)
- {
- struct factory_data *data = f54->factory_data;
- struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
- int sel_status;
- set_default_result(data);
- sel_status = data->cmd_param[0];
- dev_info(&rmi4_data->i2c_client->dev, "%s : %d\n", __func__, sel_status);
- sprintf(data->cmd_buff, "switch to %s", sel_status ? "TSP_SUB" : "TSP_MAIN");
- if(rmi4_data->tsp_probe && (sel_status == TSP_MAIN || sel_status == TSP_SUB)){
- gpio_set_value(rmi4_data->dt_data->tsp_sel, sel_status);
- snprintf(data->cmd_buff, sizeof(data->cmd_buff), "OK");
- data->cmd_state = CMD_STATUS_OK;
- } else {
- snprintf(data->cmd_buff, sizeof(data->cmd_buff), "NG");
- data->cmd_state = CMD_STATUS_FAIL;
- }
- set_cmd_result(data, data->cmd_buff, strlen(data->cmd_buff));
- mutex_lock(&data->cmd_lock);
- data->cmd_is_running = false;
- mutex_unlock(&data->cmd_lock);
- return;
- }
- static void not_support_cmd(void)
- {
- struct factory_data *data = f54->factory_data;
- set_default_result(data);
- sprintf(data->cmd_buff, "%s", tostring(NA));
- set_cmd_result(data, data->cmd_buff, strlen(data->cmd_buff));
- data->cmd_state = CMD_STATUS_NOT_APPLICABLE;
- }
- #endif
- static ssize_t synaptics_rmi4_f54_status_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- return snprintf(buf, PAGE_SIZE, "%u\n", f54->status);
- }
- static ssize_t synaptics_rmi4_f54_report_size_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- return snprintf(buf, PAGE_SIZE, "%u\n", f54->report_size);
- }
- static ssize_t synaptics_rmi4_f54_no_auto_cal_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- return snprintf(buf, PAGE_SIZE, "%u\n", f54->no_auto_cal);
- }
- static ssize_t synaptics_rmi4_f54_no_auto_cal_store(struct device *dev,
- struct device_attribute *attr, const char *buf, size_t count)
- {
- int retval;
- unsigned char data;
- unsigned long setting;
- struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
- retval = kstrtoul(buf, 10, &setting);
- if (retval)
- return retval;
- if (setting > 1)
- return -EINVAL;
- retval = f54->fn_ptr->read(rmi4_data,
- f54->control_base_addr,
- &data,
- sizeof(data));
- if (retval < 0) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Failed to read control register\n",
- __func__);
- return retval;
- }
- if ((data & NO_AUTO_CAL_MASK) == setting)
- return count;
- data = (data & ~NO_AUTO_CAL_MASK) | (data & NO_AUTO_CAL_MASK);
- retval = f54->fn_ptr->write(rmi4_data,
- f54->control_base_addr,
- &data,
- sizeof(data));
- if (retval < 0) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Failed to write control register\n",
- __func__);
- return retval;
- }
- f54->no_auto_cal = (setting == 1);
- return count;
- }
- static ssize_t synaptics_rmi4_f54_report_type_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- return snprintf(buf, PAGE_SIZE, "%u\n", f54->report_type);
- }
- static ssize_t synaptics_rmi4_f54_report_type_store(struct device *dev,
- struct device_attribute *attr, const char *buf, size_t count)
- {
- int retval;
- unsigned char data;
- unsigned long setting;
- struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
- retval = kstrtoul(buf, 10, &setting);
- if (retval)
- return retval;
- if (!is_report_type_valid((enum f54_report_types)setting)) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Report type not supported by driver\n",
- __func__);
- return -EINVAL;
- }
- mutex_lock(&f54->status_mutex);
- if (f54->status != STATUS_BUSY) {
- f54->report_type = (enum f54_report_types)setting;
- data = (unsigned char)setting;
- retval = f54->fn_ptr->write(rmi4_data,
- f54->data_base_addr,
- &data,
- sizeof(data));
- mutex_unlock(&f54->status_mutex);
- if (retval < 0) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Failed to write data register\n",
- __func__);
- return retval;
- }
- return count;
- } else {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Previous get report still ongoing\n",
- __func__);
- mutex_unlock(&f54->status_mutex);
- return -EINVAL;
- }
- }
- static ssize_t synaptics_rmi4_f54_fifoindex_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- int retval;
- unsigned char data[2];
- struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
- retval = f54->fn_ptr->read(rmi4_data,
- f54->data_base_addr + DATA_REPORT_INDEX_OFFSET,
- data,
- sizeof(data));
- if (retval < 0) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Failed to read data registers\n",
- __func__);
- return retval;
- }
- batohs(&f54->fifoindex, data);
- return snprintf(buf, PAGE_SIZE, "%u\n", f54->fifoindex);
- }
- static ssize_t synaptics_rmi4_f54_fifoindex_store(struct device *dev,
- struct device_attribute *attr, const char *buf, size_t count)
- {
- int retval;
- unsigned char data[2];
- unsigned long setting;
- struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
- retval = kstrtoul(buf, 10, &setting);
- if (retval)
- return retval;
- f54->fifoindex = setting;
- hstoba(data, (unsigned short)setting);
- retval = f54->fn_ptr->write(rmi4_data,
- f54->data_base_addr + DATA_REPORT_INDEX_OFFSET,
- data,
- sizeof(data));
- if (retval < 0) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Failed to write data registers\n",
- __func__);
- return retval;
- }
- return count;
- }
- static ssize_t synaptics_rmi4_f54_do_preparation_store(struct device *dev,
- struct device_attribute *attr, const char *buf, size_t count)
- {
- int retval;
- unsigned long setting;
- struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
- retval = kstrtoul(buf, 10, &setting);
- if (retval)
- return retval;
- if (setting != 1)
- return -EINVAL;
- mutex_lock(&f54->status_mutex);
- if (f54->status != STATUS_IDLE) {
- if (f54->status != STATUS_BUSY) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Invalid status (%d)\n",
- __func__, f54->status);
- } else {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Previous get report still ongoing\n",
- __func__);
- }
- mutex_unlock(&f54->status_mutex);
- return -EBUSY;
- }
- mutex_unlock(&f54->status_mutex);
- retval = do_preparation();
- if (retval < 0) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Failed to do preparation\n",
- __func__);
- return retval;
- }
- return count;
- }
- static ssize_t synaptics_rmi4_f54_get_report_store(struct device *dev,
- struct device_attribute *attr, const char *buf, size_t count)
- {
- int retval;
- unsigned char command;
- unsigned long setting;
- struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
- retval = kstrtoul(buf, 10, &setting);
- if (retval)
- return retval;
- if (setting != 1)
- return -EINVAL;
- command = (unsigned char)COMMAND_GET_REPORT;
- if (!is_report_type_valid(f54->report_type)) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Invalid report type\n",
- __func__);
- return -EINVAL;
- }
- mutex_lock(&f54->status_mutex);
- if (f54->status != STATUS_IDLE) {
- if (f54->status != STATUS_BUSY) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Invalid status (%d)\n",
- __func__, f54->status);
- } else {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Previous get report still ongoing\n",
- __func__);
- }
- mutex_unlock(&f54->status_mutex);
- return -EBUSY;
- }
- set_interrupt(true);
- f54->status = STATUS_BUSY;
- retval = f54->fn_ptr->write(rmi4_data,
- f54->command_base_addr,
- &command,
- sizeof(command));
- mutex_unlock(&f54->status_mutex);
- if (retval < 0) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Failed to write get report command\n",
- __func__);
- return retval;
- }
- #ifdef WATCHDOG_HRTIMER
- hrtimer_start(&f54->watchdog,
- ktime_set(WATCHDOG_TIMEOUT_S, 0),
- HRTIMER_MODE_REL);
- #endif
- return count;
- }
- static ssize_t synaptics_rmi4_f54_force_cal_store(struct device *dev,
- struct device_attribute *attr, const char *buf, size_t count)
- {
- int retval;
- unsigned char command;
- unsigned long setting;
- struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
- retval = kstrtoul(buf, 10, &setting);
- if (retval)
- return retval;
- if (setting != 1)
- return count;
- command = (unsigned char)COMMAND_FORCE_CAL;
- if (f54->status == STATUS_BUSY)
- return -EBUSY;
- retval = f54->fn_ptr->write(rmi4_data,
- f54->command_base_addr,
- &command,
- sizeof(command));
- if (retval < 0) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Failed to write force cal command\n",
- __func__);
- return retval;
- }
- return count;
- }
- simple_show_func_unsigned(query, num_of_rx_electrodes)
- simple_show_func_unsigned(query, num_of_tx_electrodes)
- simple_show_func_unsigned(query, has_image16)
- simple_show_func_unsigned(query, has_image8)
- simple_show_func_unsigned(query, has_baseline)
- simple_show_func_unsigned(query, clock_rate)
- simple_show_func_unsigned(query, touch_controller_family)
- simple_show_func_unsigned(query, has_pixel_touch_threshold_adjustment)
- simple_show_func_unsigned(query, has_sensor_assignment)
- simple_show_func_unsigned(query, has_interference_metric)
- simple_show_func_unsigned(query, has_sense_frequency_control)
- simple_show_func_unsigned(query, has_firmware_noise_mitigation)
- simple_show_func_unsigned(query, has_two_byte_report_rate)
- simple_show_func_unsigned(query, has_one_byte_report_rate)
- simple_show_func_unsigned(query, has_relaxation_control)
- simple_show_func_unsigned(query, curve_compensation_mode)
- simple_show_func_unsigned(query, has_iir_filter)
- simple_show_func_unsigned(query, has_cmn_removal)
- simple_show_func_unsigned(query, has_cmn_maximum)
- simple_show_func_unsigned(query, has_touch_hysteresis)
- simple_show_func_unsigned(query, has_edge_compensation)
- simple_show_func_unsigned(query, has_per_frequency_noise_control)
- simple_show_func_unsigned(query, has_signal_clarity)
- simple_show_func_unsigned(query, number_of_sensing_frequencies)
- show_store_func_unsigned(control, reg_0, no_relax)
- show_store_func_unsigned(control, reg_0, no_scan)
- show_store_func_unsigned(control, reg_1, bursts_per_cluster)
- show_store_func_unsigned(control, reg_2, saturation_cap)
- show_store_func_unsigned(control, reg_3, pixel_touch_threshold)
- show_store_func_unsigned(control, reg_4__6, rx_feedback_cap)
- show_store_func_unsigned(control, reg_4__6, low_ref_cap)
- show_store_func_unsigned(control, reg_4__6, low_ref_feedback_cap)
- show_store_func_unsigned(control, reg_4__6, low_ref_polarity)
- show_store_func_unsigned(control, reg_4__6, high_ref_cap)
- show_store_func_unsigned(control, reg_4__6, high_ref_feedback_cap)
- show_store_func_unsigned(control, reg_4__6, high_ref_polarity)
- show_store_func_unsigned(control, reg_7, cbc_cap)
- show_store_func_unsigned(control, reg_7, cbc_polarity)
- show_store_func_unsigned(control, reg_7, cbc_tx_carrier_selection)
- show_store_func_unsigned(control, reg_8__9, integration_duration)
- show_store_func_unsigned(control, reg_8__9, reset_duration)
- show_store_func_unsigned(control, reg_10, noise_sensing_bursts_per_image)
- show_store_func_unsigned(control, reg_12__13, slow_relaxation_rate)
- show_store_func_unsigned(control, reg_12__13, fast_relaxation_rate)
- show_store_func_unsigned(control, reg_14, rxs_on_xaxis)
- show_store_func_unsigned(control, reg_14, curve_comp_on_txs)
- show_store_func_unsigned(control, reg_20, disable_noise_mitigation)
- show_store_func_unsigned(control, reg_21, freq_shift_noise_threshold)
- show_store_func_unsigned(control, reg_22__26, medium_noise_threshold)
- show_store_func_unsigned(control, reg_22__26, high_noise_threshold)
- show_store_func_unsigned(control, reg_22__26, noise_density)
- show_store_func_unsigned(control, reg_22__26, frame_count)
- show_store_func_unsigned(control, reg_27, iir_filter_coef)
- show_store_func_unsigned(control, reg_28, quiet_threshold)
- show_store_func_unsigned(control, reg_29, cmn_filter_disable)
- show_store_func_unsigned(control, reg_30, cmn_filter_max)
- show_store_func_unsigned(control, reg_31, touch_hysteresis)
- show_store_func_unsigned(control, reg_32__35, rx_low_edge_comp)
- show_store_func_unsigned(control, reg_32__35, rx_high_edge_comp)
- show_store_func_unsigned(control, reg_32__35, tx_low_edge_comp)
- show_store_func_unsigned(control, reg_32__35, tx_high_edge_comp)
- show_store_func_unsigned(control, reg_41, no_signal_clarity)
- show_replicated_func_unsigned(control, reg_15, sensor_rx_assignment)
- show_replicated_func_unsigned(control, reg_16, sensor_tx_assignment)
- show_replicated_func_unsigned(control, reg_17, disable)
- show_replicated_func_unsigned(control, reg_17, filter_bandwidth)
- show_replicated_func_unsigned(control, reg_19, stretch_duration)
- show_replicated_func_unsigned(control, reg_38, noise_control_1)
- show_replicated_func_unsigned(control, reg_39, noise_control_2)
- show_replicated_func_unsigned(control, reg_40, noise_control_3)
- show_store_replicated_func_unsigned(control, reg_36, axis1_comp)
- show_store_replicated_func_unsigned(control, reg_37, axis2_comp)
- static ssize_t synaptics_rmi4_f54_burst_count_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- int retval;
- int size = 0;
- unsigned char ii;
- unsigned char *temp;
- struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
- mutex_lock(&f54->control_mutex);
- retval = f54->fn_ptr->read(rmi4_data,
- f54->control.reg_17->address,
- (unsigned char *)f54->control.reg_17->data,
- f54->control.reg_17->length);
- if (retval < 0) {
- dev_dbg(&rmi4_data->i2c_client->dev,
- "%s: Failed to read control reg_17\n",
- __func__);
- }
- retval = f54->fn_ptr->read(rmi4_data,
- f54->control.reg_18->address,
- (unsigned char *)f54->control.reg_18->data,
- f54->control.reg_18->length);
- if (retval < 0) {
- dev_dbg(&rmi4_data->i2c_client->dev,
- "%s: Failed to read control reg_18\n",
- __func__);
- }
- mutex_unlock(&f54->control_mutex);
- temp = buf;
- for (ii = 0; ii < f54->control.reg_17->length; ii++) {
- retval = snprintf(temp, PAGE_SIZE - size, "%u ", (1 << 8) *
- f54->control.reg_17->data[ii].burst_count_b8__10 +
- f54->control.reg_18->data[ii].burst_count_b0__7);
- if (retval < 0) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Faild to write output\n",
- __func__);
- return retval;
- }
- size += retval;
- temp += retval;
- }
- retval = snprintf(temp, PAGE_SIZE - size, "\n");
- if (retval < 0) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Faild to write null terminator\n",
- __func__);
- return retval;
- }
- return size + retval;
- }
- static ssize_t synaptics_rmi4_f54_data_read(struct file *data_file,
- struct kobject *kobj, struct bin_attribute *attributes,
- char *buf, loff_t pos, size_t count)
- {
- struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
- mutex_lock(&f54->data_mutex);
- if (count < f54->report_size) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Report type %d data size (%d) too large\n",
- __func__, f54->report_type, f54->report_size);
- mutex_unlock(&f54->data_mutex);
- return -EINVAL;
- }
- if (f54->report_data) {
- memcpy(buf, f54->report_data, f54->report_size);
- mutex_unlock(&f54->data_mutex);
- return f54->report_size;
- } else {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Report type %d data not available\n",
- __func__, f54->report_type);
- mutex_unlock(&f54->data_mutex);
- return -EINVAL;
- }
- }
- static int synaptics_rmi4_f54_set_sysfs(void)
- {
- int retval;
- int reg_num;
- struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
- f54->attr_dir = kobject_create_and_add("f54",
- &rmi4_data->input_dev->dev.kobj);
- if (!f54->attr_dir) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Failed to create sysfs directory\n",
- __func__);
- goto exit_1;
- }
- retval = sysfs_create_bin_file(f54->attr_dir, &dev_report_data);
- if (retval < 0) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Failed to create sysfs bin file\n",
- __func__);
- goto exit_2;
- }
- retval = sysfs_create_group(f54->attr_dir, &attr_group);
- if (retval < 0) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Failed to create sysfs attributes\n",
- __func__);
- goto exit_3;
- }
- for (reg_num = 0; reg_num < ARRAY_SIZE(attrs_ctrl_regs); reg_num++) {
- if (attrs_ctrl_regs_exist[reg_num]) {
- retval = sysfs_create_group(f54->attr_dir,
- &attrs_ctrl_regs[reg_num]);
- if (retval < 0) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Failed to create sysfs attributes\n",
- __func__);
- goto exit_4;
- }
- }
- }
- return 0;
- exit_4:
- sysfs_remove_group(f54->attr_dir, &attr_group);
- for (reg_num--; reg_num >= 0; reg_num--)
- sysfs_remove_group(f54->attr_dir, &attrs_ctrl_regs[reg_num]);
- exit_3:
- sysfs_remove_bin_file(f54->attr_dir, &dev_report_data);
- exit_2:
- kobject_put(f54->attr_dir);
- exit_1:
- return -ENODEV;
- }
- static int synaptics_rmi4_f54_set_ctrl(void)
- {
- unsigned char length;
- unsigned char reg_num = 0;
- unsigned char num_of_sensing_freqs;
- unsigned short reg_addr = f54->control_base_addr;
- struct f54_control *control = &f54->control;
- struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
- num_of_sensing_freqs = f54->query.number_of_sensing_frequencies;
- /* control 0 */
- attrs_ctrl_regs_exist[reg_num] = true;
- control->reg_0 = kzalloc(sizeof(*(control->reg_0)),
- GFP_KERNEL);
- if (!control->reg_0)
- goto exit_no_mem;
- control->reg_0->address = reg_addr;
- reg_addr += sizeof(control->reg_0->data);
- reg_num++;
- /* control 1 */
- if ((f54->query.touch_controller_family == 0) ||
- (f54->query.touch_controller_family == 1)) {
- attrs_ctrl_regs_exist[reg_num] = true;
- control->reg_1 = kzalloc(sizeof(*(control->reg_1)),
- GFP_KERNEL);
- if (!control->reg_1)
- goto exit_no_mem;
- control->reg_1->address = reg_addr;
- reg_addr += sizeof(control->reg_1->data);
- }
- reg_num++;
- /* control 2 */
- attrs_ctrl_regs_exist[reg_num] = true;
- control->reg_2 = kzalloc(sizeof(*(control->reg_2)),
- GFP_KERNEL);
- if (!control->reg_2)
- goto exit_no_mem;
- control->reg_2->address = reg_addr;
- reg_addr += sizeof(control->reg_2->data);
- reg_num++;
- /* control 3 */
- if (f54->query.has_pixel_touch_threshold_adjustment == 1) {
- attrs_ctrl_regs_exist[reg_num] = true;
- control->reg_3 = kzalloc(sizeof(*(control->reg_3)),
- GFP_KERNEL);
- if (!control->reg_3)
- goto exit_no_mem;
- control->reg_3->address = reg_addr;
- reg_addr += sizeof(control->reg_3->data);
- }
- reg_num++;
- /* controls 4 5 6 */
- if ((f54->query.touch_controller_family == 0) ||
- (f54->query.touch_controller_family == 1)) {
- attrs_ctrl_regs_exist[reg_num] = true;
- control->reg_4__6 = kzalloc(sizeof(*(control->reg_4__6)),
- GFP_KERNEL);
- if (!control->reg_4__6)
- goto exit_no_mem;
- control->reg_4__6->address = reg_addr;
- reg_addr += sizeof(control->reg_4__6->data);
- }
- reg_num++;
- /* control 7 */
- if (f54->query.touch_controller_family == 1) {
- attrs_ctrl_regs_exist[reg_num] = true;
- control->reg_7 = kzalloc(sizeof(*(control->reg_7)),
- GFP_KERNEL);
- if (!control->reg_7)
- goto exit_no_mem;
- control->reg_7->address = reg_addr;
- reg_addr += sizeof(control->reg_7->data);
- }
- reg_num++;
- /* controls 8 9 */
- if ((f54->query.touch_controller_family == 0) ||
- (f54->query.touch_controller_family == 1)) {
- attrs_ctrl_regs_exist[reg_num] = true;
- control->reg_8__9 = kzalloc(sizeof(*(control->reg_8__9)),
- GFP_KERNEL);
- if (!control->reg_8__9)
- goto exit_no_mem;
- control->reg_8__9->address = reg_addr;
- reg_addr += sizeof(control->reg_8__9->data);
- }
- reg_num++;
- /* control 10 */
- if (f54->query.has_interference_metric == 1) {
- attrs_ctrl_regs_exist[reg_num] = true;
- control->reg_10 = kzalloc(sizeof(*(control->reg_10)),
- GFP_KERNEL);
- if (!control->reg_10)
- goto exit_no_mem;
- control->reg_10->address = reg_addr;
- reg_addr += sizeof(control->reg_10->data);
- }
- reg_num++;
- /* control 11 */
- if (f54->query.has_ctrl11 == 1) {
- attrs_ctrl_regs_exist[reg_num] = true;
- control->reg_11 = kzalloc(sizeof(*(control->reg_11)),
- GFP_KERNEL);
- if (!control->reg_11)
- goto exit_no_mem;
- control->reg_11->address = reg_addr;
- reg_addr += sizeof(control->reg_11->data);
- }
- reg_num++;
- /* controls 12 13 */
- if (f54->query.has_relaxation_control == 1) {
- attrs_ctrl_regs_exist[reg_num] = true;
- control->reg_12__13 = kzalloc(sizeof(*(control->reg_12__13)),
- GFP_KERNEL);
- if (!control->reg_12__13)
- goto exit_no_mem;
- control->reg_12__13->address = reg_addr;
- reg_addr += sizeof(control->reg_12__13->data);
- }
- reg_num++;
- /* controls 14 15 16 */
- if (f54->query.has_sensor_assignment == 1) {
- attrs_ctrl_regs_exist[reg_num] = true;
- control->reg_14 = kzalloc(sizeof(*(control->reg_14)),
- GFP_KERNEL);
- if (!control->reg_14)
- goto exit_no_mem;
- control->reg_14->address = reg_addr;
- reg_addr += sizeof(control->reg_14->data);
- control->reg_15 = kzalloc(sizeof(*(control->reg_15)),
- GFP_KERNEL);
- if (!control->reg_15)
- goto exit_no_mem;
- control->reg_15->length = f54->query.num_of_rx_electrodes;
- control->reg_15->data = kzalloc(control->reg_15->length *
- sizeof(*(control->reg_15->data)), GFP_KERNEL);
- if (!control->reg_15->data)
- goto exit_no_mem;
- control->reg_15->address = reg_addr;
- reg_addr += control->reg_15->length;
- control->reg_16 = kzalloc(sizeof(*(control->reg_16)),
- GFP_KERNEL);
- if (!control->reg_16)
- goto exit_no_mem;
- control->reg_16->length = f54->query.num_of_tx_electrodes;
- control->reg_16->data = kzalloc(control->reg_16->length *
- sizeof(*(control->reg_16->data)), GFP_KERNEL);
- if (!control->reg_16->data)
- goto exit_no_mem;
- control->reg_16->address = reg_addr;
- reg_addr += control->reg_16->length;
- }
- reg_num++;
- /* controls 17 18 19 */
- if (f54->query.has_sense_frequency_control == 1) {
- attrs_ctrl_regs_exist[reg_num] = true;
- length = num_of_sensing_freqs;
- control->reg_17 = kzalloc(sizeof(*(control->reg_17)),
- GFP_KERNEL);
- if (!control->reg_17)
- goto exit_no_mem;
- control->reg_17->length = length;
- control->reg_17->data = kzalloc(length *
- sizeof(*(control->reg_17->data)), GFP_KERNEL);
- if (!control->reg_17->data)
- goto exit_no_mem;
- control->reg_17->address = reg_addr;
- reg_addr += length;
- control->reg_18 = kzalloc(sizeof(*(control->reg_18)),
- GFP_KERNEL);
- if (!control->reg_18)
- goto exit_no_mem;
- control->reg_18->length = length;
- control->reg_18->data = kzalloc(length *
- sizeof(*(control->reg_18->data)), GFP_KERNEL);
- if (!control->reg_18->data)
- goto exit_no_mem;
- control->reg_18->address = reg_addr;
- reg_addr += length;
- control->reg_19 = kzalloc(sizeof(*(control->reg_19)),
- GFP_KERNEL);
- if (!control->reg_19)
- goto exit_no_mem;
- control->reg_19->length = length;
- control->reg_19->data = kzalloc(length *
- sizeof(*(control->reg_19->data)), GFP_KERNEL);
- if (!control->reg_19->data)
- goto exit_no_mem;
- control->reg_19->address = reg_addr;
- reg_addr += length;
- }
- reg_num++;
- /* control 20 */
- attrs_ctrl_regs_exist[reg_num] = true;
- control->reg_20 = kzalloc(sizeof(*(control->reg_20)),
- GFP_KERNEL);
- if (!control->reg_20)
- goto exit_no_mem;
- control->reg_20->address = reg_addr;
- reg_addr += sizeof(control->reg_20->data);
- reg_num++;
- /* control 21 */
- if (f54->query.has_sense_frequency_control == 1) {
- attrs_ctrl_regs_exist[reg_num] = true;
- control->reg_21 = kzalloc(sizeof(*(control->reg_21)),
- GFP_KERNEL);
- if (!control->reg_21)
- goto exit_no_mem;
- control->reg_21->address = reg_addr;
- reg_addr += sizeof(control->reg_21->data);
- }
- reg_num++;
- /* controls 22 23 24 25 26 */
- if (f54->query.has_firmware_noise_mitigation == 1) {
- attrs_ctrl_regs_exist[reg_num] = true;
- control->reg_22__26 = kzalloc(sizeof(*(control->reg_22__26)),
- GFP_KERNEL);
- if (!control->reg_22__26)
- goto exit_no_mem;
- control->reg_22__26->address = reg_addr;
- reg_addr += sizeof(control->reg_22__26->data);
- }
- reg_num++;
- /* control 27 */
- if (f54->query.has_iir_filter == 1) {
- attrs_ctrl_regs_exist[reg_num] = true;
- control->reg_27 = kzalloc(sizeof(*(control->reg_27)),
- GFP_KERNEL);
- if (!control->reg_27)
- goto exit_no_mem;
- control->reg_27->address = reg_addr;
- reg_addr += sizeof(control->reg_27->data);
- }
- reg_num++;
- /* control 28 */
- if (f54->query.has_firmware_noise_mitigation == 1) {
- attrs_ctrl_regs_exist[reg_num] = true;
- control->reg_28 = kzalloc(sizeof(*(control->reg_28)),
- GFP_KERNEL);
- if (!control->reg_28)
- goto exit_no_mem;
- control->reg_28->address = reg_addr;
- reg_addr += sizeof(control->reg_28->data);
- }
- reg_num++;
- /* control 29 */
- if (f54->query.has_cmn_removal == 1) {
- attrs_ctrl_regs_exist[reg_num] = true;
- control->reg_29 = kzalloc(sizeof(*(control->reg_29)),
- GFP_KERNEL);
- if (!control->reg_29)
- goto exit_no_mem;
- control->reg_29->address = reg_addr;
- reg_addr += sizeof(control->reg_29->data);
- }
- reg_num++;
- /* control 30 */
- if (f54->query.has_cmn_maximum == 1) {
- attrs_ctrl_regs_exist[reg_num] = true;
- control->reg_30 = kzalloc(sizeof(*(control->reg_30)),
- GFP_KERNEL);
- if (!control->reg_30)
- goto exit_no_mem;
- control->reg_30->address = reg_addr;
- reg_addr += sizeof(control->reg_30->data);
- }
- reg_num++;
- /* control 31 */
- if (f54->query.has_touch_hysteresis == 1) {
- attrs_ctrl_regs_exist[reg_num] = true;
- control->reg_31 = kzalloc(sizeof(*(control->reg_31)),
- GFP_KERNEL);
- if (!control->reg_31)
- goto exit_no_mem;
- control->reg_31->address = reg_addr;
- reg_addr += sizeof(control->reg_31->data);
- }
- reg_num++;
- /* controls 32 33 34 35 */
- if (f54->query.has_edge_compensation == 1) {
- attrs_ctrl_regs_exist[reg_num] = true;
- control->reg_32__35 = kzalloc(sizeof(*(control->reg_32__35)),
- GFP_KERNEL);
- if (!control->reg_32__35)
- goto exit_no_mem;
- control->reg_32__35->address = reg_addr;
- reg_addr += sizeof(control->reg_32__35->data);
- }
- reg_num++;
- /* control 36 */
- if ((f54->query.curve_compensation_mode == 1) ||
- (f54->query.curve_compensation_mode == 2)) {
- attrs_ctrl_regs_exist[reg_num] = true;
- if (f54->query.curve_compensation_mode == 1) {
- length = max(f54->query.num_of_rx_electrodes,
- f54->query.num_of_tx_electrodes);
- } else if (f54->query.curve_compensation_mode == 2) {
- length = f54->query.num_of_rx_electrodes;
- }
- control->reg_36 = kzalloc(sizeof(*(control->reg_36)),
- GFP_KERNEL);
- if (!control->reg_36)
- goto exit_no_mem;
- control->reg_36->length = length;
- control->reg_36->data = kzalloc(length *
- sizeof(*(control->reg_36->data)), GFP_KERNEL);
- if (!control->reg_36->data)
- goto exit_no_mem;
- control->reg_36->address = reg_addr;
- reg_addr += length;
- }
- reg_num++;
- /* control 37 */
- if (f54->query.curve_compensation_mode == 2) {
- attrs_ctrl_regs_exist[reg_num] = true;
- control->reg_37 = kzalloc(sizeof(*(control->reg_37)),
- GFP_KERNEL);
- if (!control->reg_37)
- goto exit_no_mem;
- control->reg_37->length = f54->query.num_of_tx_electrodes;
- control->reg_37->data = kzalloc(control->reg_37->length *
- sizeof(*(control->reg_37->data)), GFP_KERNEL);
- if (!control->reg_37->data)
- goto exit_no_mem;
- control->reg_37->address = reg_addr;
- reg_addr += control->reg_37->length;
- }
- reg_num++;
- /* controls 38 39 40 */
- if (f54->query.has_per_frequency_noise_control == 1) {
- attrs_ctrl_regs_exist[reg_num] = true;
- control->reg_38 = kzalloc(sizeof(*(control->reg_38)),
- GFP_KERNEL);
- if (!control->reg_38)
- goto exit_no_mem;
- control->reg_38->length = num_of_sensing_freqs;
- control->reg_38->data = kzalloc(control->reg_38->length *
- sizeof(*(control->reg_38->data)), GFP_KERNEL);
- if (!control->reg_38->data)
- goto exit_no_mem;
- control->reg_38->address = reg_addr;
- reg_addr += control->reg_38->length;
- control->reg_39 = kzalloc(sizeof(*(control->reg_39)),
- GFP_KERNEL);
- if (!control->reg_39)
- goto exit_no_mem;
- control->reg_39->length = num_of_sensing_freqs;
- control->reg_39->data = kzalloc(control->reg_39->length *
- sizeof(*(control->reg_39->data)), GFP_KERNEL);
- if (!control->reg_39->data)
- goto exit_no_mem;
- control->reg_39->address = reg_addr;
- reg_addr += control->reg_39->length;
- control->reg_40 = kzalloc(sizeof(*(control->reg_40)),
- GFP_KERNEL);
- if (!control->reg_40)
- goto exit_no_mem;
- control->reg_40->length = num_of_sensing_freqs;
- control->reg_40->data = kzalloc(control->reg_40->length *
- sizeof(*(control->reg_40->data)), GFP_KERNEL);
- if (!control->reg_40->data)
- goto exit_no_mem;
- control->reg_40->address = reg_addr;
- reg_addr += control->reg_40->length;
- }
- reg_num++;
- /* control 41 */
- if (f54->query.has_signal_clarity == 1) {
- attrs_ctrl_regs_exist[reg_num] = true;
- control->reg_41 = kzalloc(sizeof(*(control->reg_41)),
- GFP_KERNEL);
- if (!control->reg_41)
- goto exit_no_mem;
- control->reg_41->address = reg_addr;
- reg_addr += sizeof(control->reg_41->data);
- }
- reg_num++;
- return 0;
- exit_no_mem:
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Failed to alloc mem for control registers\n",
- __func__);
- return -ENOMEM;
- }
- #ifdef FACTORY_MODE
- static int synaptics_rmi4_f54_get_report_type(int type)
- {
- int retval;
- char buf[3];
- unsigned char patience = 5;
- memset(buf, 0x00, sizeof(buf));
- snprintf(buf, 3, "%u\n", type);
- retval = synaptics_rmi4_f54_report_type_store(NULL, NULL, buf, 2);
- if (retval != 2)
- return 0;
- memset(buf, 0x00, sizeof(buf));
- snprintf(buf, 3, "%u\n", CMD_GET_REPORT);
- retval = synaptics_rmi4_f54_get_report_store(NULL, NULL, buf, 2);
- if (retval != 2)
- return 0;
- do {
- msleep(1000);
- if (f54->status == STATUS_IDLE)
- break;
- } while (--patience > 0);
- if ((f54->report_size == 0) || (f54->status != STATUS_IDLE))
- return 0;
- else
- return 1;
- }
- #endif
- static void synaptics_rmi4_f54_status_work(struct work_struct *work)
- {
- int retval;
- unsigned char report_index[2];
- struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
- if (f54->status != STATUS_BUSY)
- return;
- set_report_size();
- if (f54->report_size == 0) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Report data size = 0\n",
- __func__);
- retval = -EINVAL;
- goto error_exit;
- }
- if (f54->data_buffer_size < f54->report_size) {
- mutex_lock(&f54->data_mutex);
- if (f54->data_buffer_size)
- kfree(f54->report_data);
- f54->report_data = kzalloc(f54->report_size, GFP_KERNEL);
- if (!f54->report_data) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Failed to alloc mem for data buffer\n",
- __func__);
- f54->data_buffer_size = 0;
- mutex_unlock(&f54->data_mutex);
- retval = -ENOMEM;
- goto error_exit;
- }
- f54->data_buffer_size = f54->report_size;
- mutex_unlock(&f54->data_mutex);
- }
- report_index[0] = 0;
- report_index[1] = 0;
- retval = f54->fn_ptr->write(rmi4_data,
- f54->data_base_addr + DATA_REPORT_INDEX_OFFSET,
- report_index,
- sizeof(report_index));
- if (retval < 0) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Failed to write report data index\n",
- __func__);
- retval = -EINVAL;
- goto error_exit;
- }
- retval = f54->fn_ptr->read(rmi4_data,
- f54->data_base_addr + DATA_REPORT_DATA_OFFSET,
- f54->report_data,
- f54->report_size);
- if (retval < 0) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Failed to read report data\n",
- __func__);
- retval = -EINVAL;
- goto error_exit;
- }
- retval = STATUS_IDLE;
- #ifdef RAW_HEX
- print_raw_hex_report();
- #endif
- #ifdef HUMAN_READABLE
- print_image_report();
- #endif
- error_exit:
- mutex_lock(&f54->status_mutex);
- set_interrupt(false);
- f54->status = retval;
- mutex_unlock(&f54->status_mutex);
- return;
- }
- static void synaptics_rmi4_f54_attn(struct synaptics_rmi4_data *rmi4_data,
- unsigned char intr_mask)
- {
- if (f54->intr_mask & intr_mask) {
- queue_delayed_work(f54->status_workqueue,
- &f54->status_work,
- msecs_to_jiffies(STATUS_WORK_INTERVAL));
- }
- return;
- }
- int synaptics_rmi4_f54_set_control(struct synaptics_rmi4_data *rmi4_data)
- {
- int retval;
- unsigned short ii;
- unsigned char page;
- unsigned char intr_count = 0;
- unsigned char intr_offset;
- struct synaptics_rmi4_fn_desc rmi_fd;
- f54->rmi4_data = rmi4_data;
- f54->fn_ptr->read = rmi4_data->i2c_read;
- f54->fn_ptr->write = rmi4_data->i2c_write;
- f54->fn_ptr->enable = rmi4_data->irq_enable;
- for (page = 0; page < PAGES_TO_SERVICE; page++) {
- for (ii = PDT_START; ii > PDT_END; ii -= PDT_ENTRY_SIZE) {
- ii |= (page << 8);
- retval = f54->fn_ptr->read(rmi4_data,
- ii,
- (unsigned char *)&rmi_fd,
- sizeof(rmi_fd));
- if (retval < 0)
- goto err_out;
- if (!rmi_fd.fn_number)
- break;
- if (rmi_fd.fn_number == SYNAPTICS_RMI4_F54)
- goto f54_found;
- intr_count += (rmi_fd.intr_src_count & MASK_3BIT);
- }
- }
- f54_found:
- f54->query_base_addr = rmi_fd.query_base_addr | (page << 8);
- f54->control_base_addr = rmi_fd.ctrl_base_addr | (page << 8);
- f54->data_base_addr = rmi_fd.data_base_addr | (page << 8);
- f54->command_base_addr = rmi_fd.cmd_base_addr | (page << 8);
- dev_info(&rmi4_data->i2c_client->dev,
- "%s: query_base_addr[0x%x] control_base_addr[0x%x] data_base_addr[0x%x] command_base_addr[0x%x]\n",
- __func__, f54->query_base_addr, f54->control_base_addr, f54->data_base_addr, f54->command_base_addr);
- f54->intr_reg_num = (intr_count + 7) / 8;
- if (f54->intr_reg_num != 0)
- f54->intr_reg_num -= 1;
- f54->intr_mask = 0;
- intr_offset = intr_count % 8;
- for (ii = intr_offset;
- ii < ((rmi_fd.intr_src_count & MASK_3BIT) +
- intr_offset);
- ii++) {
- f54->intr_mask |= 1 << ii;
- }
- retval = f54->fn_ptr->read(rmi4_data,
- f54->query_base_addr,
- f54->query.data,
- sizeof(f54->query.data));
- if (retval < 0) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Failed to read query registers\n",
- __func__);
- goto err_out;
- }
- retval = synaptics_rmi4_f54_set_ctrl();
- if (retval < 0) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Failed to set up control registers\n",
- __func__);
- goto err_out;
- }
- return 0;
- err_out:
- return retval;
- }
- static int synaptics_rmi4_f54_init(struct synaptics_rmi4_data *rmi4_data)
- {
- int retval;
- unsigned short ii;
- #ifdef FACTORY_MODE
- unsigned char rx = rmi4_data->num_of_rx;
- unsigned char tx = rmi4_data->num_of_tx;
- struct factory_data *factory_data;
- #endif
- f54 = kzalloc(sizeof(*f54), GFP_KERNEL);
- if (!f54) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Failed to alloc mem for f54\n",
- __func__);
- retval = -ENOMEM;
- goto exit;
- }
- f54->fn_ptr = kzalloc(sizeof(*(f54->fn_ptr)), GFP_KERNEL);
- if (!f54->fn_ptr) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Failed to alloc mem for fn_ptr\n",
- __func__);
- retval = -ENOMEM;
- goto exit_free_f54;
- }
- retval = synaptics_rmi4_f54_set_control(rmi4_data);
- if (retval < 0) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Failed to control f54.\n",
- __func__);
- goto exit_free_control;
- }
- mutex_init(&f54->status_mutex);
- mutex_init(&f54->data_mutex);
- mutex_init(&f54->control_mutex);
- retval = synaptics_rmi4_f54_set_sysfs();
- if (retval < 0) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Failed to create sysfs entries\n",
- __func__);
- goto exit_sysfs;
- }
- #ifdef FACTORY_MODE
- factory_data = kzalloc(sizeof(*factory_data), GFP_KERNEL);
- if (!factory_data) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Failed to alloc mem for factory_data\n",
- __func__);
- retval = -ENOMEM;
- goto exit_factory_data;
- }
- factory_data->rawcap_data = kzalloc(2 * rx * tx, GFP_KERNEL);
- if (!factory_data->rawcap_data) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Failed to alloc mem for rawcap_data\n",
- __func__);
- retval = -ENOMEM;
- goto exit_rawcap_data;
- }
- factory_data->delta_data = kzalloc(2 * rx * tx, GFP_KERNEL);
- if (!factory_data->delta_data) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Failed to alloc mem for delta_data\n",
- __func__);
- retval = -ENOMEM;
- goto exit_delta_data;
- }
- factory_data->abscap_data = kzalloc(4 * rx * tx, GFP_KERNEL);
- if (!factory_data->abscap_data) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Failed to alloc mem for abscap_data\n",
- __func__);
- retval = -ENOMEM;
- goto exit_abscap_data;
- }
- factory_data->absdelta_data = kzalloc(4 * rx * tx, GFP_KERNEL);
- if (!factory_data->abscap_data) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Failed to alloc mem for abscap_data\n",
- __func__);
- retval = -ENOMEM;
- goto exit_absdelta_data;
- }
- factory_data->trx_short = kzalloc(TREX_DATA_SIZE, GFP_KERNEL);
- if (!factory_data->trx_short) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Failed to alloc mem for trx_short\n",
- __func__);
- retval = -ENOMEM;
- goto exit_trx_short;
- }
- INIT_LIST_HEAD(&factory_data->cmd_list_head);
- for (ii = 0; ii < ARRAY_SIZE(ft_cmds); ii++)
- list_add_tail(&ft_cmds[ii].list, &factory_data->cmd_list_head);
- mutex_init(&factory_data->cmd_lock);
- factory_data->cmd_is_running = false;
- factory_data->fac_dev_ts = device_create(sec_class,
- NULL, 0, f54, "tsp");
- retval = IS_ERR(factory_data->fac_dev_ts);
- if (retval) {
- dev_err(&rmi4_data->i2c_client->dev, "%s: Failed to create device for the sysfs\n",
- __func__);
- retval = IS_ERR(factory_data->fac_dev_ts);
- goto exit_cmd_attr_group;
- }
- retval = sysfs_create_group(&factory_data->fac_dev_ts->kobj,
- &cmd_attr_group);
- if (retval < 0) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Failed to create sysfs attributes\n",
- __func__);
- goto exit_cmd_attr_group;
- }
- retval = sysfs_create_link(&factory_data->fac_dev_ts->kobj,
- &rmi4_data->input_dev->dev.kobj, "input");
- if (retval < 0) {
- dev_err(&rmi4_data->i2c_client->dev,
- "%s: Failed to create link\n", __func__);
- }
- f54->factory_data = factory_data;
- #endif
- f54->status_workqueue =
- create_singlethread_workqueue("f54_status_workqueue");
- INIT_DELAYED_WORK(&f54->status_work,
- synaptics_rmi4_f54_status_work);
- #ifdef WATCHDOG_HRTIMER
- /* Watchdog timer to catch unanswered get report commands */
- hrtimer_init(&f54->watchdog, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
- f54->watchdog.function = get_report_timeout;
- /* Work function to do actual cleaning up */
- INIT_WORK(&f54->timeout_work, timeout_set_status);
- #endif
- return 0;
- #ifdef FACTORY_MODE
- exit_cmd_attr_group:
- kfree(factory_data->trx_short);
- kfree(factory_data->abscap_data);
- kfree(factory_data->absdelta_data);
- kfree(factory_data->rawcap_data);
- kfree(factory_data->delta_data);
- exit_trx_short:
- exit_absdelta_data:
- exit_abscap_data:
- exit_delta_data:
- exit_rawcap_data:
- kfree(factory_data);
- exit_factory_data:
- remove_sysfs();
- #endif
- exit_sysfs:
- exit_free_control:
- free_control_mem();
- kfree(f54->fn_ptr);
- exit_free_f54:
- kfree(f54);
- exit:
- return retval;
- }
- static void synaptics_rmi4_f54_remove(struct synaptics_rmi4_data *rmi4_data)
- {
- if (!f54)
- return;
- #ifdef WATCHDOG_HRTIMER
- hrtimer_cancel(&f54->watchdog);
- #endif
- cancel_delayed_work_sync(&f54->status_work);
- flush_workqueue(f54->status_workqueue);
- destroy_workqueue(f54->status_workqueue);
- #ifdef FACTORY_MODE
- sysfs_remove_group(&f54->factory_data->fac_dev_ts->kobj, &cmd_attr_group);
- kfree(f54->factory_data->trx_short);
- kfree(f54->factory_data->abscap_data);
- kfree(f54->factory_data->absdelta_data);
- kfree(f54->factory_data->rawcap_data);
- kfree(f54->factory_data->delta_data);
- kfree(f54->factory_data);
- #endif
- remove_sysfs();
- free_control_mem();
- if (f54->data_buffer_size)
- kfree(f54->report_data);
- kfree(f54->fn_ptr);
- kfree(f54);
- f54 = NULL;
- return;
- }
- int rmi4_f54_module_register(void)
- {
- int retval;
- retval = synaptics_rmi4_new_function(RMI_F54,
- synaptics_rmi4_f54_init,
- synaptics_rmi4_f54_remove,
- synaptics_rmi4_f54_attn);
- return retval;
- }
|