synaptics_i2c_rmi.c 126 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850
  1. /* Synaptics Register Mapped Interface (RMI4) I2C Physical Layer Driver.
  2. * Copyright (c) 2007-2012, Synaptics Incorporated
  3. *
  4. * This software is licensed under the terms of the GNU General Public
  5. * License version 2, as published by the Free Software Foundation, and
  6. * may be copied, distributed, and modified under those terms.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. */
  14. #include <linux/kernel.h>
  15. #include <linux/module.h>
  16. #include <asm/unaligned.h>
  17. #include <mach/cpufreq.h>
  18. #include <linux/slab.h>
  19. #include <linux/i2c.h>
  20. #include <linux/interrupt.h>
  21. #include <linux/delay.h>
  22. #include <linux/input.h>
  23. #include <linux/input/mt.h>
  24. #include <linux/gpio.h>
  25. #include <linux/regulator/consumer.h>
  26. #ifdef CONFIG_HAS_EARLYSUSPEND
  27. #include <linux/earlysuspend.h>
  28. #endif
  29. #include "synaptics_i2c_rmi.h"
  30. #include "synaptics_rmi.h"
  31. #include <linux/of_gpio.h>
  32. #include <linux/regulator/consumer.h>
  33. #define DRIVER_NAME "synaptics_rmi4_i2c"
  34. #define PROXIMITY
  35. #define TYPE_B_PROTOCOL
  36. #ifdef SURFACE_TOUCH
  37. #define EDGE_SWIPE
  38. #endif
  39. #undef USE_SENSOR_SLEEP
  40. /*#define REPORT_2D_Z*/
  41. #define REPORT_2D_W
  42. #define F12_FINGERS_TO_SUPPORT 10
  43. #define RPT_TYPE (1 << 0)
  44. #define RPT_X_LSB (1 << 1)
  45. #define RPT_X_MSB (1 << 2)
  46. #define RPT_Y_LSB (1 << 3)
  47. #define RPT_Y_MSB (1 << 4)
  48. #define RPT_Z (1 << 5)
  49. #define RPT_WX (1 << 6)
  50. #define RPT_WY (1 << 7)
  51. #define RPT_DEFAULT (RPT_TYPE | RPT_X_LSB | RPT_X_MSB | RPT_Y_LSB | RPT_Y_MSB)
  52. #ifdef CONFIG_GLOVE_TOUCH
  53. #define GLOVE_FEATURE_EN 0x20
  54. #define GLOVE_CLEAR_DEFAULT 0x00
  55. #endif
  56. #ifdef PROXIMITY
  57. #define USE_CUSTOM_REZERO
  58. #define HOVER_Z_MAX (255)
  59. #define FINGER_HOVER_EN (1 << 0)
  60. #define FINGER_HOVER_DIS (0 << 0)
  61. #define AIR_SWIPE_EN (1 << 1)
  62. #define LARGE_OBJ_EN (1 << 2)
  63. #define HOVER_PINCH_EN (1 << 3)
  64. #define NO_PROXIMITY_ON_TOUCH_EN (1 << 5)
  65. #define CONTINUOUS_LOAD_REPORT_EN (1 << 6)
  66. #define SLEEP_PROXIMITY (1 << 7)
  67. #define PROXIMITY_DEFAULT (NO_PROXIMITY_ON_TOUCH_EN)
  68. #define PROXIMITY_ENABLE (PROXIMITY_DEFAULT | FINGER_HOVER_EN)
  69. #define HAS_FINGER_HOVER (1 << 0)
  70. #define HAS_AIR_SWIPE (1 << 1)
  71. #define HAS_LARGE_OBJ (1 << 2)
  72. #define HAS_HOVER_PINCH (1 << 3)
  73. #define HAS_EDGE_SWIPE (1 << 4)
  74. #define HAS_SINGLE_FINGER (1 << 5)
  75. #define F51_VERSION 0x41
  76. #define F51_PROXIMITY_ENABLES_OFFSET (0)
  77. #define F51_CTRL54_OFFSET 99
  78. #ifdef USE_CUSTOM_REZERO
  79. #define F51_GENERAL_CONTROL_OFFSET (1)
  80. #define F51_CTRL78_OFFSET 115
  81. #endif
  82. #ifdef EDGE_SWIPE
  83. #define EDGE_SWIPE_DATA_OFFSET 8
  84. #define EDGE_SWIPE_WIDTH_MAX 255
  85. #define EDGE_SWIPE_PALM_MAX 1
  86. #endif
  87. #define F51_FINGER_TIMEOUT 50 /* ms */
  88. #endif
  89. #define POLLING_PERIOD 1 /* ms */
  90. #define SYN_I2C_RETRY_TIMES 3
  91. #define MAX_F11_TOUCH_WIDTH 15
  92. #define CHECK_STATUS_TIMEOUT_MS 200
  93. #define STATUS_NO_ERROR 0x00
  94. #define STATUS_RESET_OCCURRED 0x01
  95. #define STATUS_INVALID_CONFIG 0x02
  96. #define STATUS_DEVICE_FAILURE 0x03
  97. #define STATUS_CONFIG_CRC_FAILURE 0x04
  98. #define STATUS_FIRMWARE_CRC_FAILURE 0x05
  99. #define STATUS_CRC_IN_PROGRESS 0x06
  100. #define F01_STD_QUERY_LEN 21
  101. #define F01_BUID_ID_OFFSET 18
  102. #define F11_STD_QUERY_LEN 9
  103. #define F11_STD_CTRL_LEN 10
  104. #define F11_STD_DATA_LEN 12
  105. #define NORMAL_OPERATION (0 << 0)
  106. #define SENSOR_SLEEP (1 << 0)
  107. #define NO_SLEEP_OFF (0 << 2)
  108. #define NO_SLEEP_ON (1 << 2)
  109. #define CHARGER_CONNECTED (1 << 5)
  110. #define CHARGER_DISCONNECTED 0xDF
  111. #define CONFIGURED (1 << 7)
  112. #define TSP_NEEDTO_REBOOT (-ECONNREFUSED)
  113. #define MAX_TSP_REBOOT 3
  114. #if defined(CONFIG_SEC_MELIUSCA_PROJECT)
  115. #define SYNAPTICS_MAX_X_SIZE 719
  116. #define SYNAPTICS_MAX_Y_SIZE 1279
  117. #else
  118. #define SYNAPTICS_MAX_X_SIZE 1079
  119. #define SYNAPTICS_MAX_Y_SIZE 1919
  120. #endif
  121. #define SYNAPTICS_MAX_WIDTH SYNAPTICS_MAX_Y_SIZE
  122. #define NUM_RX 28
  123. #define NUM_TX 16
  124. #ifdef TSP_PATTERN_TRACKING_METHOD
  125. #define MAX_GHOSTCHECK_FINGER 10
  126. #define MAX_GHOSTTOUCH_COUNT 5
  127. #define MAX_COUNT_TOUCHSYSREBOOT 4
  128. #define MAX_GHOSTTOUCH_BY_PATTERNTRACKING 3
  129. #define PATTERN_TRACKING_DISTANCE 4
  130. #define TSP_REBOOT_PENDING_TIME 50
  131. #define MOVE_COUNT_TH 100
  132. /* Each project has different edge config,
  133. so check this value before applying pattern tracking */
  134. #define MIN_X_EDGE 17
  135. #define MAX_X_EDGE 1060 //1062
  136. #define MIN_Y_EDGE 17
  137. #define MAX_Y_EDGE 1900 // 1902
  138. /* Below is used for clearing ghost touch or for checking to system reboot. by Xtopher */
  139. static int tcount_finger[MAX_GHOSTCHECK_FINGER] = {0,0,0,0,0,0,0,0,0,0};
  140. static int touchbx[MAX_GHOSTCHECK_FINGER] = {0,0,0,0,0,0,0,0,0,0};
  141. static int touchby[MAX_GHOSTCHECK_FINGER] = {0,0,0,0,0,0,0,0,0,0};
  142. static int ghosttouchcount = 0;
  143. static bool tsp_pattern_tracking(int fingerindex, int x, int y, bool movecheck);
  144. #endif
  145. extern void mdss_dsi_panel_touchsensing(int enable);
  146. void synaptics_power_ctrl(struct synaptics_rmi4_data *rmi4_data, bool enable);
  147. static int synaptics_rmi4_i2c_read(struct synaptics_rmi4_data *rmi4_data,
  148. unsigned short addr, unsigned char *data,
  149. unsigned short length);
  150. static int synaptics_rmi4_i2c_write(struct synaptics_rmi4_data *rmi4_data,
  151. unsigned short addr, unsigned char *data,
  152. unsigned short length);
  153. static int synaptics_rmi4_reinit_device(struct synaptics_rmi4_data *rmi4_data);
  154. static int synaptics_rmi4_reset_device(struct synaptics_rmi4_data *rmi4_data);
  155. static int synaptics_rmi4_stop_device(struct synaptics_rmi4_data *rmi4_data);
  156. static int synaptics_rmi4_start_device(struct synaptics_rmi4_data *rmi4_data);
  157. #ifdef CONFIG_HAS_EARLYSUSPEND
  158. static ssize_t synaptics_rmi4_full_pm_cycle_show(struct device *dev,
  159. struct device_attribute *attr, char *buf);
  160. static ssize_t synaptics_rmi4_full_pm_cycle_store(struct device *dev,
  161. struct device_attribute *attr, const char *buf, size_t count);
  162. static void synaptics_rmi4_early_suspend(struct early_suspend *h);
  163. static void synaptics_rmi4_late_resume(struct early_suspend *h);
  164. #else
  165. static int synaptics_rmi4_suspend(struct device *dev);
  166. static int synaptics_rmi4_resume(struct device *dev);
  167. #endif
  168. #ifdef PROXIMITY
  169. static void synaptics_rmi4_f51_finger_timer(unsigned long data);
  170. static ssize_t synaptics_rmi4_f51_enables_show(struct device *dev,
  171. struct device_attribute *attr, char *buf);
  172. static ssize_t synaptics_rmi4_f51_enables_store(struct device *dev,
  173. struct device_attribute *attr, const char *buf, size_t count);
  174. #endif
  175. #ifdef USE_OPEN_CLOSE
  176. static int synaptics_rmi4_input_open(struct input_dev *dev);
  177. static void synaptics_rmi4_input_close(struct input_dev *dev);
  178. #ifdef USE_OPEN_DWORK
  179. static void synaptics_rmi4_open_work(struct work_struct *work);
  180. #endif
  181. #endif
  182. static ssize_t synaptics_rmi4_f01_reset_store(struct device *dev,
  183. struct device_attribute *attr, const char *buf, size_t count);
  184. static ssize_t synaptics_rmi4_f01_productinfo_show(struct device *dev,
  185. struct device_attribute *attr, char *buf);
  186. static ssize_t synaptics_rmi4_f01_buildid_show(struct device *dev,
  187. struct device_attribute *attr, char *buf);
  188. static ssize_t synaptics_rmi4_f01_flashprog_show(struct device *dev,
  189. struct device_attribute *attr, char *buf);
  190. static ssize_t synaptics_rmi4_0dbutton_show(struct device *dev,
  191. struct device_attribute *attr, char *buf);
  192. static ssize_t synaptics_rmi4_0dbutton_store(struct device *dev,
  193. struct device_attribute *attr, const char *buf, size_t count);
  194. struct synaptics_rmi4_f01_device_status {
  195. union {
  196. struct {
  197. unsigned char status_code:4;
  198. unsigned char reserved:2;
  199. unsigned char flash_prog:1;
  200. unsigned char unconfigured:1;
  201. } __packed;
  202. unsigned char data[1];
  203. };
  204. };
  205. struct synaptics_rmi4_f12_query_5 {
  206. union {
  207. struct {
  208. unsigned char size_of_query6;
  209. struct {
  210. unsigned char ctrl0_is_present:1;
  211. unsigned char ctrl1_is_present:1;
  212. unsigned char ctrl2_is_present:1;
  213. unsigned char ctrl3_is_present:1;
  214. unsigned char ctrl4_is_present:1;
  215. unsigned char ctrl5_is_present:1;
  216. unsigned char ctrl6_is_present:1;
  217. unsigned char ctrl7_is_present:1;
  218. } __packed;
  219. struct {
  220. unsigned char ctrl8_is_present:1;
  221. unsigned char ctrl9_is_present:1;
  222. unsigned char ctrl10_is_present:1;
  223. unsigned char ctrl11_is_present:1;
  224. unsigned char ctrl12_is_present:1;
  225. unsigned char ctrl13_is_present:1;
  226. unsigned char ctrl14_is_present:1;
  227. unsigned char ctrl15_is_present:1;
  228. } __packed;
  229. struct {
  230. unsigned char ctrl16_is_present:1;
  231. unsigned char ctrl17_is_present:1;
  232. unsigned char ctrl18_is_present:1;
  233. unsigned char ctrl19_is_present:1;
  234. unsigned char ctrl20_is_present:1;
  235. unsigned char ctrl21_is_present:1;
  236. unsigned char ctrl22_is_present:1;
  237. unsigned char ctrl23_is_present:1;
  238. } __packed;
  239. struct {
  240. unsigned char ctrl24_is_present:1;
  241. unsigned char ctrl25_is_present:1;
  242. unsigned char ctrl26_is_present:1;
  243. unsigned char ctrl27_is_present:1;
  244. unsigned char ctrl28_is_present:1;
  245. unsigned char ctrl29_is_present:1;
  246. unsigned char ctrl30_is_present:1;
  247. unsigned char ctrl31_is_present:1;
  248. } __packed;
  249. };
  250. unsigned char data[5];
  251. };
  252. };
  253. struct synaptics_rmi4_f12_query_8 {
  254. union {
  255. struct {
  256. unsigned char size_of_query9;
  257. struct {
  258. unsigned char data0_is_present:1;
  259. unsigned char data1_is_present:1;
  260. unsigned char data2_is_present:1;
  261. unsigned char data3_is_present:1;
  262. unsigned char data4_is_present:1;
  263. unsigned char data5_is_present:1;
  264. unsigned char data6_is_present:1;
  265. unsigned char data7_is_present:1;
  266. } __packed;
  267. };
  268. unsigned char data[2];
  269. };
  270. };
  271. struct synaptics_rmi4_f12_ctrl_8 {
  272. union {
  273. struct {
  274. unsigned char max_x_coord_lsb;
  275. unsigned char max_x_coord_msb;
  276. unsigned char max_y_coord_lsb;
  277. unsigned char max_y_coord_msb;
  278. unsigned char rx_pitch_lsb;
  279. unsigned char rx_pitch_msb;
  280. unsigned char tx_pitch_lsb;
  281. unsigned char tx_pitch_msb;
  282. unsigned char low_rx_clip;
  283. unsigned char high_rx_clip;
  284. unsigned char low_tx_clip;
  285. unsigned char high_tx_clip;
  286. unsigned char num_of_rx;
  287. unsigned char num_of_tx;
  288. };
  289. unsigned char data[14];
  290. };
  291. };
  292. struct synaptics_rmi4_f12_ctrl_9 {
  293. union {
  294. struct {
  295. unsigned char touch_threshold;
  296. unsigned char lift_hysteresis;
  297. unsigned char small_z_scale_factor_lsb;
  298. unsigned char small_z_scale_factor_msb;
  299. unsigned char large_z_scale_factor_lsb;
  300. unsigned char large_z_scale_factor_msb;
  301. unsigned char small_large_boundary;
  302. unsigned char wx_scale;
  303. unsigned char wx_offset;
  304. unsigned char wy_scale;
  305. unsigned char wy_offset;
  306. unsigned char x_size_lsb;
  307. unsigned char x_size_msb;
  308. unsigned char y_size_lsb;
  309. unsigned char y_size_msb;
  310. unsigned char gloved_finger;
  311. };
  312. unsigned char data[16];
  313. };
  314. };
  315. struct synaptics_rmi4_f12_ctrl_23 {
  316. union {
  317. struct {
  318. unsigned char obj_type_enable;
  319. unsigned char max_reported_objects;
  320. };
  321. unsigned char data[2];
  322. };
  323. };
  324. #ifdef CONFIG_GLOVE_TOUCH
  325. struct synaptics_rmi4_f12_ctrl_26 {
  326. union {
  327. struct {
  328. unsigned char glove_feature_enable;
  329. };
  330. unsigned char data[1];
  331. };
  332. };
  333. #endif
  334. struct synaptics_rmi4_f12_finger_data {
  335. unsigned char object_type_and_status;
  336. unsigned char x_lsb;
  337. unsigned char x_msb;
  338. unsigned char y_lsb;
  339. unsigned char y_msb;
  340. #ifdef REPORT_2D_Z
  341. unsigned char z;
  342. #endif
  343. #ifdef REPORT_2D_W
  344. unsigned char wx;
  345. unsigned char wy;
  346. #endif
  347. };
  348. struct synaptics_rmi4_f1a_query {
  349. union {
  350. struct {
  351. unsigned char max_button_count:3;
  352. unsigned char reserved:5;
  353. unsigned char has_general_control:1;
  354. unsigned char has_interrupt_enable:1;
  355. unsigned char has_multibutton_select:1;
  356. unsigned char has_tx_rx_map:1;
  357. unsigned char has_perbutton_threshold:1;
  358. unsigned char has_release_threshold:1;
  359. unsigned char has_strongestbtn_hysteresis:1;
  360. unsigned char has_filter_strength:1;
  361. } __packed;
  362. unsigned char data[2];
  363. };
  364. };
  365. struct synaptics_rmi4_f1a_control_0 {
  366. union {
  367. struct {
  368. unsigned char multibutton_report:2;
  369. unsigned char filter_mode:2;
  370. unsigned char reserved:4;
  371. } __packed;
  372. unsigned char data[1];
  373. };
  374. };
  375. struct synaptics_rmi4_f1a_control_3_4 {
  376. unsigned char transmitterbutton;
  377. unsigned char receiverbutton;
  378. };
  379. struct synaptics_rmi4_f1a_control {
  380. struct synaptics_rmi4_f1a_control_0 general_control;
  381. unsigned char *button_int_enable;
  382. unsigned char *multi_button;
  383. struct synaptics_rmi4_f1a_control_3_4 *electrode_map;
  384. unsigned char *button_threshold;
  385. unsigned char button_release_threshold;
  386. unsigned char strongest_button_hysteresis;
  387. unsigned char filter_strength;
  388. };
  389. struct synaptics_rmi4_f1a_handle {
  390. int button_bitmask_size;
  391. unsigned char button_count;
  392. unsigned char valid_button_count;
  393. unsigned char *button_data_buffer;
  394. unsigned char *button_map;
  395. struct synaptics_rmi4_f1a_query button_query;
  396. struct synaptics_rmi4_f1a_control button_control;
  397. };
  398. struct synaptics_rmi4_f34_ctrl_3 {
  399. union {
  400. struct {
  401. unsigned char fw_release_month;
  402. unsigned char fw_release_date;
  403. unsigned char fw_release_revision;
  404. unsigned char fw_release_version;
  405. };
  406. unsigned char data[4];
  407. };
  408. };
  409. struct synaptics_rmi4_f34_fn_ptr {
  410. int (*read)(struct synaptics_rmi4_data *rmi4_data, unsigned short addr,
  411. unsigned char *data, unsigned short length);
  412. int (*write)(struct synaptics_rmi4_data *rmi4_data, unsigned short addr,
  413. unsigned char *data, unsigned short length);
  414. int (*enable)(struct synaptics_rmi4_data *rmi4_data, bool enable);
  415. };
  416. struct synaptics_rmi4_f34_handle {
  417. unsigned char status;
  418. unsigned char cmd;
  419. unsigned short bootloaderid;
  420. unsigned short blocksize;
  421. unsigned short imageblockcount;
  422. unsigned short configblockcount;
  423. unsigned short blocknum;
  424. unsigned short query_base_addr;
  425. unsigned short control_base_addr;
  426. unsigned short data_base_addr;
  427. bool inflashprogmode;
  428. unsigned char intr_mask;
  429. struct mutex attn_mutex;
  430. struct synaptics_rmi4_f34_fn_ptr *fn_ptr;
  431. };
  432. #ifdef PROXIMITY
  433. struct synaptics_rmi4_f51_query {
  434. union {
  435. struct {
  436. unsigned char query_register_count;
  437. unsigned char data_register_count;
  438. unsigned char control_register_count;
  439. unsigned char command_register_count;
  440. unsigned char proximity_controls;
  441. };
  442. unsigned char data[5];
  443. };
  444. };
  445. struct synaptics_rmi4_f51_data {
  446. union {
  447. struct {
  448. unsigned char finger_hover_det:1;
  449. unsigned char air_swipe_det:1;
  450. unsigned char large_obj_det:1;
  451. unsigned char f1a_data0_b3:1;
  452. unsigned char hover_pinch_det:1;
  453. unsigned char f1a_data0_b5__7:3;
  454. unsigned char hover_finger_x_4__11;
  455. unsigned char hover_finger_y_4__11;
  456. unsigned char hover_finger_xy_0__3;
  457. unsigned char hover_finger_z;
  458. unsigned char air_swipe_dir_0:1;
  459. unsigned char air_swipe_dir_1:1;
  460. unsigned char f1a_data3_b2__4:3;
  461. unsigned char object_present:1;
  462. unsigned char large_obj_act:2;
  463. } __packed;
  464. unsigned char proximity_data[6];
  465. };
  466. #ifdef EDGE_SWIPE
  467. union {
  468. struct {
  469. unsigned char edge_swipe_x_lsb;
  470. unsigned char edge_swipe_x_msb;
  471. unsigned char edge_swipe_y_lsb;
  472. unsigned char edge_swipe_y_msb;
  473. unsigned char edge_swipe_z;
  474. unsigned char edge_swipe_wx;
  475. unsigned char edge_swipe_wy;
  476. unsigned char edge_swipe_mm;
  477. unsigned char edge_swipe_dg;
  478. } __packed;
  479. unsigned char edge_swipe_data[9];
  480. };
  481. #endif
  482. };
  483. #ifdef EDGE_SWIPE
  484. struct synaptics_rmi4_surface {
  485. int width_major;
  486. int palm;
  487. int angle;
  488. int wx;
  489. int wy;
  490. };
  491. #endif
  492. struct synaptics_rmi4_f51_handle {
  493. unsigned char proximity_enables;
  494. unsigned short proximity_enables_addr;
  495. unsigned char num_of_data_sources;
  496. #ifdef USE_CUSTOM_REZERO
  497. unsigned short proximity_custom_rezero_addr;
  498. #endif
  499. unsigned char proximity_controls;
  500. #ifdef EDGE_SWIPE
  501. struct synaptics_rmi4_surface surface_data;
  502. #endif
  503. struct synaptics_rmi4_data *rmi4_data;
  504. };
  505. #endif
  506. struct synaptics_rmi4_exp_fn {
  507. enum exp_fn fn_type;
  508. bool initialized;
  509. int (*func_init)(struct synaptics_rmi4_data *rmi4_data);
  510. void (*func_remove)(struct synaptics_rmi4_data *rmi4_data);
  511. void (*func_attn)(struct synaptics_rmi4_data *rmi4_data,
  512. unsigned char intr_mask);
  513. struct list_head link;
  514. };
  515. static struct device_attribute attrs[] = {
  516. #ifdef CONFIG_HAS_EARLYSUSPEND
  517. __ATTR(full_pm_cycle, (S_IRUGO | S_IWUSR | S_IWGRP),
  518. synaptics_rmi4_full_pm_cycle_show,
  519. synaptics_rmi4_full_pm_cycle_store),
  520. #endif
  521. #ifdef PROXIMITY
  522. __ATTR(proximity_enables, (S_IRUGO | S_IWUSR | S_IWGRP),
  523. synaptics_rmi4_f51_enables_show,
  524. synaptics_rmi4_f51_enables_store),
  525. #endif
  526. __ATTR(reset, S_IWUSR | S_IWGRP,
  527. synaptics_rmi4_show_error,
  528. synaptics_rmi4_f01_reset_store),
  529. __ATTR(productinfo, S_IRUGO,
  530. synaptics_rmi4_f01_productinfo_show,
  531. synaptics_rmi4_store_error),
  532. __ATTR(buildid, S_IRUGO,
  533. synaptics_rmi4_f01_buildid_show,
  534. synaptics_rmi4_store_error),
  535. __ATTR(flashprog, S_IRUGO,
  536. synaptics_rmi4_f01_flashprog_show,
  537. synaptics_rmi4_store_error),
  538. __ATTR(0dbutton, (S_IRUGO | S_IWUSR | S_IWGRP),
  539. synaptics_rmi4_0dbutton_show,
  540. synaptics_rmi4_0dbutton_store),
  541. };
  542. #if !defined(CONFIG_SEC_MELIUSCA_PROJECT)
  543. static struct synaptics_rmi4_platform_data rmi4_platformdata = {
  544. // .irq_type = IRQF_TRIGGER_FALLING,
  545. /*Direct IRQ for secure input*/
  546. // .irq_type = IRQF_TRIGGER_RISING | IRQF_ONESHOT,
  547. // .gpio = GPIO_TOUCH_IRQ,
  548. .sensor_max_x = SYNAPTICS_MAX_X_SIZE,
  549. .sensor_max_y = SYNAPTICS_MAX_Y_SIZE,
  550. .max_touch_width = 28,
  551. /*.gpio_config = synaptics_gpio_setup,*/
  552. //.f1a_button_map = &tm1940_f1a_button_map,
  553. // .register_cb = synaptics_tsp_register_callback,
  554. .tsppwr_1p8_en = 480,
  555. .firmware_name = NULL,
  556. .fac_firmware_name = NULL,
  557. .num_of_rx = NUM_RX,
  558. .num_of_tx = NUM_TX,
  559. #if defined(CONFIG_TOUCHSCREEN_SYNAPTICS_PREVENT_HSYNC_LEAKAGE)
  560. .hsync_onoff = mdss_dsi_panel_hsync_onoff,
  561. #endif
  562. };
  563. #else
  564. static unsigned char tm1940_f1a_button_codes[] = {KEY_MENU, KEY_BACK};
  565. static struct synaptics_rmi_f1a_button_map tm1940_f1a_button_map = {
  566. .nbuttons = ARRAY_SIZE(tm1940_f1a_button_codes),
  567. .map = tm1940_f1a_button_codes,
  568. };
  569. static struct synaptics_rmi4_platform_data rmi4_platformdata = {
  570. // .irq_type = IRQF_TRIGGER_FALLING,
  571. /*Direct IRQ for secure input*/
  572. // .irq_type = IRQF_TRIGGER_RISING | IRQF_ONESHOT,
  573. // .gpio = GPIO_TOUCH_IRQ,
  574. .sensor_max_x = SYNAPTICS_MAX_X_SIZE,
  575. .sensor_max_y = SYNAPTICS_MAX_Y_SIZE,
  576. .max_touch_width = 28,
  577. /*.gpio_config = synaptics_gpio_setup,*/
  578. .f1a_button_map = &tm1940_f1a_button_map,
  579. // .register_cb = synaptics_tsp_register_callback,
  580. .tsppwr_1p8_en = 480,
  581. .firmware_name = NULL,
  582. .fac_firmware_name = NULL,
  583. .num_of_rx = NUM_RX,
  584. .num_of_tx = NUM_TX,
  585. };
  586. #endif
  587. static int touch_sleep_time;
  588. extern int system_rev;
  589. static struct list_head exp_fn_list;
  590. #ifdef PROXIMITY
  591. static struct synaptics_rmi4_f51_handle *f51;
  592. #endif
  593. #ifdef CONFIG_OF
  594. static int synaptics_parse_dt(struct device *dev,
  595. struct synaptics_rmi4_power_data *pdata)
  596. {
  597. struct device_node *np = dev->of_node;
  598. /* reset, irq gpio info */
  599. pdata->vdd_io_1p8 = of_get_named_gpio(np, "synaptics,tsppwr_en", 0);
  600. pdata->tsp_int = of_get_named_gpio(np, "synaptics,irq-gpio", 0);
  601. pr_err("%s tsppwr_1p8_en= %d, tsp_int= %d\n", __func__,
  602. pdata->vdd_io_1p8, pdata->tsp_int);
  603. return 0;
  604. }
  605. #else
  606. static int synaptics_parse_dt(struct device *dev,
  607. struct synaptics_rmi4_power_data *pdata)
  608. {
  609. return -ENODEV;
  610. }
  611. #endif
  612. static void synaptics_request_gpio(struct synaptics_rmi4_power_data *pdata)
  613. {
  614. int ret;
  615. pr_info("[TSP] synaptics_request_gpio\n");
  616. ret = gpio_request(pdata->vdd_io_1p8, "synaptics,tsppwr_en");
  617. if (ret) {
  618. pr_err("[TSP]%s: unable to request vdd_io_1p8 [%d]\n",
  619. __func__, pdata->vdd_io_1p8);
  620. return;
  621. }
  622. }
  623. #ifdef CONFIG_HAS_EARLYSUSPEND
  624. static ssize_t synaptics_rmi4_full_pm_cycle_show(struct device *dev,
  625. struct device_attribute *attr, char *buf)
  626. {
  627. struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
  628. return snprintf(buf, PAGE_SIZE, "%u\n",
  629. rmi4_data->full_pm_cycle);
  630. }
  631. static ssize_t synaptics_rmi4_full_pm_cycle_store(struct device *dev,
  632. struct device_attribute *attr, const char *buf, size_t count)
  633. {
  634. unsigned int input;
  635. struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
  636. if (sscanf(buf, "%u", &input) != 1)
  637. return -EINVAL;
  638. rmi4_data->full_pm_cycle = input > 0 ? 1 : 0;
  639. return count;
  640. }
  641. #endif
  642. #ifdef TSP_BOOSTER
  643. static void synaptics_change_dvfs_lock(struct work_struct *work)
  644. {
  645. struct synaptics_rmi4_data *rmi4_data =
  646. container_of(work,
  647. struct synaptics_rmi4_data, work_dvfs_chg.work);
  648. int retval = 0;
  649. mutex_lock(&rmi4_data->dvfs_lock);
  650. if (rmi4_data->dvfs_boost_mode == DVFS_STAGE_DUAL) {
  651. if (rmi4_data->stay_awake) {
  652. dev_info(&rmi4_data->i2c_client->dev,
  653. "%s: do fw update, do not change cpu frequency.\n",
  654. __func__);
  655. } else {
  656. retval = set_freq_limit(DVFS_TOUCH_ID,
  657. MIN_TOUCH_LIMIT_SECOND);
  658. rmi4_data->dvfs_freq = MIN_TOUCH_LIMIT_SECOND;
  659. }
  660. } else if (rmi4_data->dvfs_boost_mode == DVFS_STAGE_SINGLE) {
  661. retval = set_freq_limit(DVFS_TOUCH_ID, -1);
  662. rmi4_data->dvfs_freq = -1;
  663. }
  664. if (retval < 0)
  665. dev_err(&rmi4_data->i2c_client->dev,
  666. "%s: booster change failed(%d).\n",
  667. __func__, retval);
  668. mutex_unlock(&rmi4_data->dvfs_lock);
  669. }
  670. static void synaptics_set_dvfs_off(struct work_struct *work)
  671. {
  672. struct synaptics_rmi4_data *rmi4_data =
  673. container_of(work,
  674. struct synaptics_rmi4_data, work_dvfs_off.work);
  675. int retval;
  676. if (rmi4_data->stay_awake) {
  677. dev_info(&rmi4_data->i2c_client->dev,
  678. "%s: do fw update, do not change cpu frequency.\n",
  679. __func__);
  680. } else {
  681. mutex_lock(&rmi4_data->dvfs_lock);
  682. retval = set_freq_limit(DVFS_TOUCH_ID, -1);
  683. rmi4_data->dvfs_freq = -1;
  684. if (retval < 0)
  685. dev_err(&rmi4_data->i2c_client->dev,
  686. "%s: booster stop failed(%d).\n",
  687. __func__, retval);
  688. rmi4_data->dvfs_lock_status = false;
  689. mutex_unlock(&rmi4_data->dvfs_lock);
  690. }
  691. }
  692. static void synaptics_set_dvfs_lock(struct synaptics_rmi4_data *rmi4_data,
  693. int on)
  694. {
  695. int ret = 0;
  696. if (rmi4_data->dvfs_boost_mode == DVFS_STAGE_NONE) {
  697. dev_info(&rmi4_data->i2c_client->dev,
  698. "%s: DVFS stage is none(%d)\n",
  699. __func__, rmi4_data->dvfs_boost_mode);
  700. return;
  701. }
  702. mutex_lock(&rmi4_data->dvfs_lock);
  703. if (on == 0) {
  704. if (rmi4_data->dvfs_lock_status) {
  705. schedule_delayed_work(&rmi4_data->work_dvfs_off,
  706. msecs_to_jiffies(TOUCH_BOOSTER_OFF_TIME));
  707. }
  708. } else if (on > 0) {
  709. cancel_delayed_work(&rmi4_data->work_dvfs_off);
  710. if (rmi4_data->dvfs_old_stauts != on) {
  711. cancel_delayed_work(&rmi4_data->work_dvfs_chg);
  712. if (1/*!rmi4_data->dvfs_lock_status*/) {
  713. if (rmi4_data->dvfs_freq != MIN_TOUCH_LIMIT) {
  714. ret = set_freq_limit(DVFS_TOUCH_ID,
  715. MIN_TOUCH_LIMIT);
  716. rmi4_data->dvfs_freq = MIN_TOUCH_LIMIT;
  717. if (ret < 0)
  718. dev_err(&rmi4_data->i2c_client->dev,
  719. "%s: cpu first lock failed(%d)\n",
  720. __func__, ret);
  721. }
  722. schedule_delayed_work(&rmi4_data->work_dvfs_chg,
  723. msecs_to_jiffies(TOUCH_BOOSTER_CHG_TIME));
  724. rmi4_data->dvfs_lock_status = true;
  725. }
  726. }
  727. } else if (on < 0) {
  728. if (rmi4_data->dvfs_lock_status) {
  729. cancel_delayed_work(&rmi4_data->work_dvfs_off);
  730. cancel_delayed_work(&rmi4_data->work_dvfs_chg);
  731. schedule_work(&rmi4_data->work_dvfs_off.work);
  732. }
  733. }
  734. rmi4_data->dvfs_old_stauts = on;
  735. mutex_unlock(&rmi4_data->dvfs_lock);
  736. }
  737. static void synaptics_init_dvfs(struct synaptics_rmi4_data *rmi4_data)
  738. {
  739. mutex_init(&rmi4_data->dvfs_lock);
  740. rmi4_data->dvfs_boost_mode = DVFS_STAGE_DUAL;
  741. INIT_DELAYED_WORK(&rmi4_data->work_dvfs_off, synaptics_set_dvfs_off);
  742. INIT_DELAYED_WORK(&rmi4_data->work_dvfs_chg, synaptics_change_dvfs_lock);
  743. rmi4_data->dvfs_lock_status = false;
  744. }
  745. #endif
  746. #ifdef PROXIMITY
  747. static ssize_t synaptics_rmi4_f51_enables_show(struct device *dev,
  748. struct device_attribute *attr, char *buf)
  749. {
  750. if (!f51)
  751. return -ENODEV;
  752. return snprintf(buf, PAGE_SIZE, "0x%02x\n",
  753. f51->proximity_enables);
  754. }
  755. static ssize_t synaptics_rmi4_f51_enables_store(struct device *dev,
  756. struct device_attribute *attr, const char *buf, size_t count)
  757. {
  758. int retval;
  759. unsigned int input;
  760. struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
  761. if (!f51)
  762. return -ENODEV;
  763. if (sscanf(buf, "%x", &input) != 1)
  764. return -EINVAL;
  765. f51->proximity_enables = (unsigned char)input;
  766. retval = synaptics_rmi4_i2c_write(rmi4_data,
  767. f51->proximity_enables_addr,
  768. &f51->proximity_enables,
  769. sizeof(f51->proximity_enables));
  770. if (retval < 0) {
  771. dev_err(dev, "%s: Failed to write proximity enables, error = %d\n",
  772. __func__, retval);
  773. return retval;
  774. }
  775. return count;
  776. }
  777. #endif
  778. static ssize_t synaptics_rmi4_f01_reset_store(struct device *dev,
  779. struct device_attribute *attr, const char *buf, size_t count)
  780. {
  781. int retval;
  782. unsigned int reset;
  783. struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
  784. if (sscanf(buf, "%u", &reset) != 1)
  785. return -EINVAL;
  786. if (reset != 1)
  787. return -EINVAL;
  788. retval = synaptics_rmi4_reset_device(rmi4_data);
  789. if (retval < 0) {
  790. dev_err(dev,
  791. "%s: Failed to issue reset command, error = %d\n",
  792. __func__, retval);
  793. return retval;
  794. }
  795. return count;
  796. }
  797. static ssize_t synaptics_rmi4_f01_productinfo_show(struct device *dev,
  798. struct device_attribute *attr, char *buf)
  799. {
  800. struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
  801. return snprintf(buf, PAGE_SIZE, "0x%02x 0x%02x\n",
  802. (rmi4_data->rmi4_mod_info.product_info[0]),
  803. (rmi4_data->rmi4_mod_info.product_info[1]));
  804. }
  805. static ssize_t synaptics_rmi4_f01_buildid_show(struct device *dev,
  806. struct device_attribute *attr, char *buf)
  807. {
  808. unsigned int build_id;
  809. struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
  810. struct synaptics_rmi4_device_info *rmi;
  811. rmi = &(rmi4_data->rmi4_mod_info);
  812. build_id = (unsigned int)rmi->build_id[0] +
  813. (unsigned int)rmi->build_id[1] * 0x100 +
  814. (unsigned int)rmi->build_id[2] * 0x10000;
  815. return snprintf(buf, PAGE_SIZE, "%u\n",
  816. build_id);
  817. }
  818. static ssize_t synaptics_rmi4_f01_flashprog_show(struct device *dev,
  819. struct device_attribute *attr, char *buf)
  820. {
  821. int retval;
  822. struct synaptics_rmi4_f01_device_status device_status;
  823. struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
  824. retval = synaptics_rmi4_i2c_read(rmi4_data,
  825. rmi4_data->f01_data_base_addr,
  826. device_status.data,
  827. sizeof(device_status.data));
  828. if (retval < 0) {
  829. dev_err(dev,
  830. "%s: Failed to read device status, error = %d\n",
  831. __func__, retval);
  832. return retval;
  833. }
  834. return snprintf(buf, PAGE_SIZE, "%u\n",
  835. device_status.flash_prog);
  836. }
  837. static ssize_t synaptics_rmi4_0dbutton_show(struct device *dev,
  838. struct device_attribute *attr, char *buf)
  839. {
  840. struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
  841. return snprintf(buf, PAGE_SIZE, "%u\n",
  842. rmi4_data->button_0d_enabled);
  843. }
  844. static ssize_t synaptics_rmi4_0dbutton_store(struct device *dev,
  845. struct device_attribute *attr, const char *buf, size_t count)
  846. {
  847. int retval;
  848. unsigned int input;
  849. unsigned char ii;
  850. unsigned char intr_enable;
  851. struct synaptics_rmi4_fn *fhandler;
  852. struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
  853. struct synaptics_rmi4_device_info *rmi;
  854. rmi = &(rmi4_data->rmi4_mod_info);
  855. if (sscanf(buf, "%u", &input) != 1)
  856. return -EINVAL;
  857. input = input > 0 ? 1 : 0;
  858. if (rmi4_data->button_0d_enabled == input)
  859. return count;
  860. if (list_empty(&rmi->support_fn_list))
  861. return -ENODEV;
  862. list_for_each_entry(fhandler, &rmi->support_fn_list, link) {
  863. if (fhandler->fn_number == SYNAPTICS_RMI4_F1A) {
  864. ii = fhandler->intr_reg_num;
  865. retval = synaptics_rmi4_i2c_read(rmi4_data,
  866. rmi4_data->f01_ctrl_base_addr + 1 + ii,
  867. &intr_enable,
  868. sizeof(intr_enable));
  869. if (retval < 0)
  870. return retval;
  871. if (input == 1)
  872. intr_enable |= fhandler->intr_mask;
  873. else
  874. intr_enable &= ~fhandler->intr_mask;
  875. retval = synaptics_rmi4_i2c_write(rmi4_data,
  876. rmi4_data->f01_ctrl_base_addr + 1 + ii,
  877. &intr_enable,
  878. sizeof(intr_enable));
  879. if (retval < 0)
  880. return retval;
  881. }
  882. }
  883. rmi4_data->button_0d_enabled = input;
  884. return count;
  885. }
  886. /**
  887. * synaptics_rmi4_set_page()
  888. *
  889. * Called by synaptics_rmi4_i2c_read() and synaptics_rmi4_i2c_write().
  890. *
  891. * This function writes to the page select register to switch to the
  892. * assigned page.
  893. */
  894. static int synaptics_rmi4_set_page(struct synaptics_rmi4_data *rmi4_data,
  895. unsigned int address)
  896. {
  897. int retval = 0;
  898. unsigned char retry;
  899. unsigned char buf[PAGE_SELECT_LEN];
  900. unsigned char page;
  901. struct i2c_client *i2c = rmi4_data->i2c_client;
  902. page = ((address >> 8) & MASK_8BIT);
  903. if (page != rmi4_data->current_page) {
  904. buf[0] = MASK_8BIT;
  905. buf[1] = page;
  906. for (retry = 0; retry < SYN_I2C_RETRY_TIMES; retry++) {
  907. retval = i2c_master_send(i2c, buf, PAGE_SELECT_LEN);
  908. if (retval != PAGE_SELECT_LEN) {
  909. if((rmi4_data->tsp_probe != true)&&(retry>=1)){
  910. dev_err(&i2c->dev,
  911. "%s: TSP needs to reboot \n",__func__);
  912. retval = TSP_NEEDTO_REBOOT;
  913. return retval;
  914. }
  915. dev_err(&i2c->dev,
  916. "%s: I2C retry = %d, i2c_master_send retval = %d\n",
  917. __func__, retry + 1, retval);
  918. if (retval == 0)
  919. retval = -EAGAIN;
  920. msleep(20);
  921. } else {
  922. rmi4_data->current_page = page;
  923. break;
  924. }
  925. }
  926. } else {
  927. retval = PAGE_SELECT_LEN;
  928. }
  929. return retval;
  930. }
  931. /**
  932. * synaptics_rmi4_i2c_read()
  933. *
  934. * Called by various functions in this driver, and also exported to
  935. * other expansion Function modules such as rmi_dev.
  936. *
  937. * This function reads data of an arbitrary length from the sensor,
  938. * starting from an assigned register address of the sensor, via I2C
  939. * with a retry mechanism.
  940. */
  941. static int synaptics_rmi4_i2c_read(struct synaptics_rmi4_data *rmi4_data,
  942. unsigned short addr, unsigned char *data, unsigned short length)
  943. {
  944. int retval;
  945. unsigned char retry;
  946. unsigned char buf;
  947. struct i2c_msg msg[] = {
  948. {
  949. .addr = rmi4_data->i2c_client->addr,
  950. .flags = 0,
  951. .len = 1,
  952. .buf = &buf,
  953. },
  954. {
  955. .addr = rmi4_data->i2c_client->addr,
  956. .flags = I2C_M_RD,
  957. .len = length,
  958. .buf = data,
  959. },
  960. };
  961. buf = addr & MASK_8BIT;
  962. mutex_lock(&(rmi4_data->rmi4_io_ctrl_mutex));
  963. if (rmi4_data->touch_stopped) {
  964. dev_err(&rmi4_data->i2c_client->dev, "%s: Sensor stopped\n",
  965. __func__);
  966. retval = 0;
  967. goto exit;
  968. }
  969. retval = synaptics_rmi4_set_page(rmi4_data, addr);
  970. if (retval != PAGE_SELECT_LEN)
  971. goto exit;
  972. for (retry = 0; retry < SYN_I2C_RETRY_TIMES; retry++) {
  973. if (i2c_transfer(rmi4_data->i2c_client->adapter, msg, 2) == 2) {
  974. retval = length;
  975. break;
  976. }
  977. dev_err(&rmi4_data->i2c_client->dev, "%s: I2C retry %d\n",
  978. __func__, retry + 1);
  979. msleep(20);
  980. }
  981. if (retry == SYN_I2C_RETRY_TIMES) {
  982. dev_err(&rmi4_data->i2c_client->dev,
  983. "%s: I2C read over retry limit\n",
  984. __func__);
  985. retval = -EIO;
  986. }
  987. exit:
  988. mutex_unlock(&(rmi4_data->rmi4_io_ctrl_mutex));
  989. return retval;
  990. }
  991. /**
  992. * synaptics_rmi4_i2c_write()
  993. *
  994. * Called by various functions in this driver, and also exported to
  995. * other expansion Function modules such as rmi_dev.
  996. *
  997. * This function writes data of an arbitrary length to the sensor,
  998. * starting from an assigned register address of the sensor, via I2C with
  999. * a retry mechanism.
  1000. */
  1001. static int synaptics_rmi4_i2c_write(struct synaptics_rmi4_data *rmi4_data,
  1002. unsigned short addr, unsigned char *data, unsigned short length)
  1003. {
  1004. int retval;
  1005. unsigned char retry;
  1006. unsigned char buf[length + 1];
  1007. struct i2c_msg msg[] = {
  1008. {
  1009. .addr = rmi4_data->i2c_client->addr,
  1010. .flags = 0,
  1011. .len = length + 1,
  1012. .buf = buf,
  1013. }
  1014. };
  1015. mutex_lock(&(rmi4_data->rmi4_io_ctrl_mutex));
  1016. if (rmi4_data->touch_stopped) {
  1017. dev_err(&rmi4_data->i2c_client->dev, "%s: Sensor stopped\n",
  1018. __func__);
  1019. retval = 0;
  1020. goto exit;
  1021. }
  1022. retval = synaptics_rmi4_set_page(rmi4_data, addr);
  1023. if (retval != PAGE_SELECT_LEN)
  1024. goto exit;
  1025. buf[0] = addr & MASK_8BIT;
  1026. memcpy(&buf[1], &data[0], length);
  1027. for (retry = 0; retry < SYN_I2C_RETRY_TIMES; retry++) {
  1028. if (i2c_transfer(rmi4_data->i2c_client->adapter, msg, 1) == 1) {
  1029. retval = length;
  1030. break;
  1031. }
  1032. dev_err(&rmi4_data->i2c_client->dev,
  1033. "%s: I2C retry %d\n",
  1034. __func__, retry + 1);
  1035. msleep(20);
  1036. }
  1037. if (retry == SYN_I2C_RETRY_TIMES) {
  1038. dev_err(&rmi4_data->i2c_client->dev,
  1039. "%s: I2C write over retry limit\n",
  1040. __func__);
  1041. retval = -EIO;
  1042. }
  1043. exit:
  1044. mutex_unlock(&(rmi4_data->rmi4_io_ctrl_mutex));
  1045. return retval;
  1046. }
  1047. #ifdef TSP_PATTERN_TRACKING_METHOD
  1048. static void clear_tcount(void)
  1049. {
  1050. int i;
  1051. for(i=0;i<MAX_GHOSTCHECK_FINGER;i++){
  1052. tcount_finger[i] = 0;
  1053. touchbx[i] = 0;
  1054. touchby[i] = 0;
  1055. }
  1056. }
  1057. static int diff_two_point(int x, int y, int oldx, int oldy)
  1058. {
  1059. int diffx,diffy;
  1060. int distance;
  1061. diffx = x-oldx;
  1062. diffy = y-oldy;
  1063. distance = abs(diffx) + abs(diffy);
  1064. if(distance < PATTERN_TRACKING_DISTANCE) return 1;
  1065. else return 0;
  1066. }
  1067. static bool IsEdgeArea(int x, int y)
  1068. {
  1069. bool fEdge = false;
  1070. if((x <= MIN_X_EDGE)||(x >= MAX_X_EDGE)||(y <= MIN_Y_EDGE)||(y >= MAX_Y_EDGE))fEdge = true;
  1071. return fEdge;
  1072. }
  1073. /* To do forced calibration when ghost touch occured at the same point
  1074. for several second. Xtopher */
  1075. static bool tsp_pattern_tracking(int fingerindex, int x, int y, bool movecheck)
  1076. {
  1077. int max_ghosttouch_th = MAX_GHOSTTOUCH_COUNT;
  1078. bool ghosttouch = false;
  1079. #ifdef PATTERN_TRACKING_FOR_FULLSCREEN
  1080. if(!IsEdgeArea(x,y)){
  1081. if(movecheck == true) return ghosttouch;
  1082. max_ghosttouch_th = MAX_GHOSTTOUCH_COUNT*2;
  1083. }
  1084. #else
  1085. if(!IsEdgeArea(x,y)) return ghosttouch;
  1086. #endif
  1087. //if((touchbx[i] == x)&&(touchby[i] == y))
  1088. if(diff_two_point(x,y, touchbx[fingerindex], touchby[fingerindex]))
  1089. {
  1090. tcount_finger[fingerindex]++;
  1091. }
  1092. else
  1093. {
  1094. tcount_finger[fingerindex] = 0;
  1095. }
  1096. touchbx[fingerindex] = x;
  1097. touchby[fingerindex] = y;
  1098. if(tcount_finger[fingerindex]>= max_ghosttouch_th){
  1099. clear_tcount();
  1100. ghosttouch = true;
  1101. return ghosttouch;
  1102. }
  1103. return ghosttouch;
  1104. }
  1105. #endif
  1106. /**
  1107. * synaptics_rmi4_f11_abs_report()
  1108. *
  1109. * Called by synaptics_rmi4_report_touch() when valid Function $11
  1110. * finger data has been detected.
  1111. *
  1112. * This function reads the Function $11 data registers, determines the
  1113. * status of each finger supported by the Function, processes any
  1114. * necessary coordinate manipulation, reports the finger data to
  1115. * the input subsystem, and returns the number of fingers detected.
  1116. */
  1117. static int synaptics_rmi4_f11_abs_report(struct synaptics_rmi4_data *rmi4_data,
  1118. struct synaptics_rmi4_fn *fhandler)
  1119. {
  1120. int retval;
  1121. unsigned char touch_count = 0; /* number of touch points */
  1122. unsigned char reg_index;
  1123. unsigned char finger;
  1124. unsigned char fingers_supported;
  1125. unsigned char num_of_finger_status_regs;
  1126. unsigned char finger_shift;
  1127. unsigned char finger_status;
  1128. unsigned char data_reg_blk_size;
  1129. unsigned char finger_status_reg[3];
  1130. unsigned char data[F11_STD_DATA_LEN];
  1131. unsigned short data_addr;
  1132. unsigned short data_offset;
  1133. int x;
  1134. int y;
  1135. int wx;
  1136. int wy;
  1137. /*
  1138. * The number of finger status registers is determined by the
  1139. * maximum number of fingers supported - 2 bits per finger. So
  1140. * the number of finger status registers to read is:
  1141. * register_count = ceil(max_num_of_fingers / 4)
  1142. */
  1143. fingers_supported = fhandler->num_of_data_points;
  1144. num_of_finger_status_regs = (fingers_supported + 3) / 4;
  1145. data_addr = fhandler->full_addr.data_base;
  1146. data_reg_blk_size = fhandler->size_of_data_register_block;
  1147. retval = synaptics_rmi4_i2c_read(rmi4_data,
  1148. data_addr,
  1149. finger_status_reg,
  1150. num_of_finger_status_regs);
  1151. if (retval < 0)
  1152. return 0;
  1153. for (finger = 0; finger < fingers_supported; finger++) {
  1154. reg_index = finger / 4;
  1155. finger_shift = (finger % 4) * 2;
  1156. finger_status = (finger_status_reg[reg_index] >> finger_shift)
  1157. & MASK_2BIT;
  1158. /*
  1159. * Each 2-bit finger status field represents the following:
  1160. * 00 = finger not present
  1161. * 01 = finger present and data accurate
  1162. * 10 = finger present but data may be inaccurate
  1163. * 11 = reserved
  1164. */
  1165. #ifdef TYPE_B_PROTOCOL
  1166. input_mt_slot(rmi4_data->input_dev, finger);
  1167. input_mt_report_slot_state(rmi4_data->input_dev,
  1168. MT_TOOL_FINGER, finger_status);
  1169. #endif
  1170. if (finger_status) {
  1171. data_offset = data_addr +
  1172. num_of_finger_status_regs +
  1173. (finger * data_reg_blk_size);
  1174. retval = synaptics_rmi4_i2c_read(rmi4_data,
  1175. data_offset,
  1176. data,
  1177. data_reg_blk_size);
  1178. if (retval < 0)
  1179. return 0;
  1180. x = (data[0] << 4) | (data[2] & MASK_4BIT);
  1181. y = (data[1] << 4) | ((data[2] >> 4) & MASK_4BIT);
  1182. wx = (data[3] & MASK_4BIT);
  1183. wy = (data[3] >> 4) & MASK_4BIT;
  1184. if (rmi4_data->board->x_flip)
  1185. x = rmi4_data->sensor_max_x - x;
  1186. if (rmi4_data->board->y_flip)
  1187. y = rmi4_data->sensor_max_y - y;
  1188. input_report_key(rmi4_data->input_dev,
  1189. BTN_TOUCH, 1);
  1190. input_report_key(rmi4_data->input_dev,
  1191. BTN_TOOL_FINGER, 1);
  1192. input_report_abs(rmi4_data->input_dev,
  1193. ABS_MT_POSITION_X, x);
  1194. input_report_abs(rmi4_data->input_dev,
  1195. ABS_MT_POSITION_Y, y);
  1196. #ifdef REPORT_2D_W
  1197. input_report_abs(rmi4_data->input_dev,
  1198. ABS_MT_TOUCH_MAJOR, max(wx, wy));
  1199. input_report_abs(rmi4_data->input_dev,
  1200. ABS_MT_TOUCH_MINOR, min(wx, wy));
  1201. #endif
  1202. #ifndef TYPE_B_PROTOCOL
  1203. input_mt_sync(rmi4_data->input_dev);
  1204. #endif
  1205. dev_dbg(&rmi4_data->i2c_client->dev,
  1206. "%s: Finger %d:\n"
  1207. "status = 0x%02x\n"
  1208. "x = %d\n"
  1209. "y = %d\n"
  1210. "wx = %d\n"
  1211. "wy = %d\n",
  1212. __func__, finger,
  1213. finger_status,
  1214. x, y, wx, wy);
  1215. touch_count++;
  1216. }
  1217. }
  1218. #ifndef TYPE_B_PROTOCOL
  1219. if (touch_count == 0)
  1220. input_mt_sync(rmi4_data->input_dev);
  1221. #endif
  1222. input_sync(rmi4_data->input_dev);
  1223. return touch_count;
  1224. }
  1225. /**
  1226. * synaptics_rmi4_f12_abs_report()
  1227. *
  1228. * Called by synaptics_rmi4_report_touch() when valid Function $12
  1229. * finger data has been detected.
  1230. *
  1231. * This function reads the Function $12 data registers, determines the
  1232. * status of each finger supported by the Function, processes any
  1233. * necessary coordinate manipulation, reports the finger data to
  1234. * the input subsystem, and returns the number of fingers detected.
  1235. */
  1236. static int synaptics_rmi4_f12_abs_report(struct synaptics_rmi4_data *rmi4_data,
  1237. struct synaptics_rmi4_fn *fhandler)
  1238. {
  1239. int retval;
  1240. unsigned char touch_count = 0; /* number of touch points */
  1241. unsigned char finger;
  1242. unsigned char fingers_supported;
  1243. unsigned char finger_status;
  1244. unsigned short data_addr;
  1245. int x;
  1246. int y;
  1247. int wx;
  1248. int wy;
  1249. struct synaptics_rmi4_f12_finger_data *data;
  1250. struct synaptics_rmi4_f12_finger_data *finger_data;
  1251. fingers_supported = fhandler->num_of_data_points;
  1252. data_addr = fhandler->full_addr.data_base;
  1253. retval = synaptics_rmi4_i2c_read(rmi4_data,
  1254. data_addr + fhandler->data1_offset,
  1255. (unsigned char *)fhandler->data,
  1256. fhandler->data_size);
  1257. if (retval < 0)
  1258. return 0;
  1259. data = (struct synaptics_rmi4_f12_finger_data *)fhandler->data;
  1260. for (finger = 0; finger < fingers_supported; finger++) {
  1261. finger_data = data + finger;
  1262. finger_status = finger_data->object_type_and_status;
  1263. if (finger_status) {
  1264. if ((finger_data->wx == 0) && (finger_data->wy == 0))
  1265. continue;
  1266. }
  1267. /*
  1268. * Each 3-bit finger status field represents the following:
  1269. * 000 = finger not present
  1270. * 001 = finger present and data accurate
  1271. * 010 = finger present but data may be inaccurate
  1272. * 011 = palm
  1273. * 110 = glove touch
  1274. */
  1275. #ifdef TYPE_B_PROTOCOL
  1276. input_mt_slot(rmi4_data->input_dev, finger);
  1277. input_mt_report_slot_state(rmi4_data->input_dev,
  1278. MT_TOOL_FINGER, finger_status);
  1279. #endif
  1280. if (finger_status) {
  1281. #ifdef CONFIG_GLOVE_TOUCH
  1282. if ((finger_status == 0x06) &&
  1283. !rmi4_data->touchkey_glove_mode_status) {
  1284. rmi4_data->touchkey_glove_mode_status = true;
  1285. input_report_switch(rmi4_data->input_dev,
  1286. SW_GLOVE, true);
  1287. } else if ((finger_status != 0x06) &&
  1288. rmi4_data->touchkey_glove_mode_status) {
  1289. rmi4_data->touchkey_glove_mode_status = false;
  1290. input_report_switch(rmi4_data->input_dev,
  1291. SW_GLOVE, false);
  1292. }
  1293. #endif
  1294. x = (finger_data->x_msb << 8) | (finger_data->x_lsb);
  1295. y = (finger_data->y_msb << 8) | (finger_data->y_lsb);
  1296. #ifdef REPORT_2D_W
  1297. wx = finger_data->wx;
  1298. wy = finger_data->wy;
  1299. #ifdef EDGE_SWIPE
  1300. if (f51) {
  1301. if ((f51->proximity_controls & HAS_EDGE_SWIPE)
  1302. && f51->surface_data.palm) {
  1303. wx = f51->surface_data.wx;
  1304. wy = f51->surface_data.wy;
  1305. }
  1306. }
  1307. #endif
  1308. #endif
  1309. if (rmi4_data->board->x_flip)
  1310. x = rmi4_data->sensor_max_x - x;
  1311. if (rmi4_data->board->y_flip)
  1312. y = rmi4_data->sensor_max_y - y;
  1313. input_report_key(rmi4_data->input_dev,
  1314. BTN_TOUCH, 1);
  1315. input_report_key(rmi4_data->input_dev,
  1316. BTN_TOOL_FINGER, 1);
  1317. input_report_abs(rmi4_data->input_dev,
  1318. ABS_MT_POSITION_X, x);
  1319. input_report_abs(rmi4_data->input_dev,
  1320. ABS_MT_POSITION_Y, y);
  1321. #ifdef REPORT_2D_W
  1322. input_report_abs(rmi4_data->input_dev,
  1323. ABS_MT_TOUCH_MAJOR, max(wx, wy));
  1324. input_report_abs(rmi4_data->input_dev,
  1325. ABS_MT_TOUCH_MINOR, min(wx, wy));
  1326. #endif
  1327. #ifdef EDGE_SWIPE
  1328. if (f51) {
  1329. if (f51->proximity_controls & HAS_EDGE_SWIPE) {
  1330. input_report_abs(rmi4_data->input_dev,
  1331. ABS_MT_WIDTH_MAJOR, f51->surface_data.width_major);
  1332. input_report_abs(rmi4_data->input_dev,
  1333. ABS_MT_PALM, f51->surface_data.palm);
  1334. }
  1335. }
  1336. #endif
  1337. #ifndef TYPE_B_PROTOCOL
  1338. input_mt_sync(rmi4_data->input_dev);
  1339. #endif
  1340. if (!rmi4_data->finger[finger].state) {
  1341. #ifdef TSP_PATTERN_TRACKING_METHOD
  1342. /* Check hopping on almost fixed point */
  1343. if(tsp_pattern_tracking(finger,x,y,false)){
  1344. dev_err(&rmi4_data->i2c_client->dev,
  1345. "Sunflower-Hopping (Pattern Tracking)\n");
  1346. cancel_delayed_work(&rmi4_data->reboot_work);
  1347. schedule_delayed_work(&rmi4_data->reboot_work,
  1348. msecs_to_jiffies(TSP_REBOOT_PENDING_TIME*6)); /* 300msec*/
  1349. touch_count = 0;
  1350. return touch_count;
  1351. }
  1352. #endif
  1353. #if !defined(CONFIG_SAMSUNG_PRODUCT_SHIP)
  1354. dev_info(&rmi4_data->i2c_client->dev, "[%d][P] 0x%02x, x = %d, y = %d, wx = %d, wy = %d\n",
  1355. finger, finger_status, x, y, wx, wy);
  1356. #else
  1357. dev_info(&rmi4_data->i2c_client->dev, "[%d][P] 0x%02x\n",
  1358. finger, finger_status);
  1359. #endif
  1360. } else {
  1361. rmi4_data->finger[finger].mcount++;
  1362. #ifdef TSP_PATTERN_TRACKING_METHOD
  1363. /* Check staying finger at one point */
  1364. if((rmi4_data->finger[finger].mcount%MOVE_COUNT_TH) == 0){
  1365. if(tsp_pattern_tracking(finger,x,y,true)){
  1366. dev_err(&rmi4_data->i2c_client->dev,
  1367. "Sunflower-Fixed (Pattern Tracking)\n");
  1368. cancel_delayed_work(&rmi4_data->reboot_work);
  1369. schedule_delayed_work(&rmi4_data->reboot_work,
  1370. msecs_to_jiffies(TSP_REBOOT_PENDING_TIME*6)); /* 300msec*/
  1371. touch_count = 0;
  1372. return touch_count;
  1373. }
  1374. }
  1375. #endif
  1376. }
  1377. touch_count++;
  1378. }
  1379. if (rmi4_data->finger[finger].state && !finger_status) {
  1380. #ifdef CONFIG_GLOVE_TOUCH
  1381. #if !defined(CONFIG_SAMSUNG_PRODUCT_SHIP)
  1382. /* TODO : Remove version information when H/W dose not changed */
  1383. dev_info(&rmi4_data->i2c_client->dev, "[%d][R] 0x%02x M[%d], Ver[%02X%02X%02X%02X]\n",
  1384. finger, finger_status, rmi4_data->finger[finger].mcount,
  1385. rmi4_data->ic_revision_of_ic, rmi4_data->panel_revision,
  1386. rmi4_data->fw_version_of_ic, rmi4_data->glove_mode_enables);
  1387. #else
  1388. dev_info(&rmi4_data->i2c_client->dev, "[%d][R] 0x%02x M[%d], Ver[%02X%02X%02X%02X]\n",
  1389. finger, finger_status, rmi4_data->finger[finger].mcount,
  1390. rmi4_data->ic_revision_of_ic, rmi4_data->panel_revision,
  1391. rmi4_data->fw_version_of_ic, rmi4_data->glove_mode_enables);
  1392. #endif
  1393. #else //CONFIG_GLOVE_TOUCH
  1394. #if !defined(CONFIG_SAMSUNG_PRODUCT_SHIP)
  1395. /* TODO : Remove version information when H/W dose not changed */
  1396. dev_info(&rmi4_data->i2c_client->dev, "[%d][R] 0x%02x M[%d], Ver[%02X%02X%02X]\n",
  1397. finger, finger_status, rmi4_data->finger[finger].mcount,
  1398. rmi4_data->ic_revision_of_ic, rmi4_data->panel_revision,
  1399. rmi4_data->fw_version_of_ic);
  1400. #else
  1401. dev_info(&rmi4_data->i2c_client->dev, "[%d][R] 0x%02x M[%d], Ver[%02X%02X%02X]\n",
  1402. finger, finger_status, rmi4_data->finger[finger].mcount,
  1403. rmi4_data->ic_revision_of_ic, rmi4_data->panel_revision,
  1404. rmi4_data->fw_version_of_ic);
  1405. #endif
  1406. #endif//CONFIG_GLOVE_TOUCH
  1407. rmi4_data->finger[finger].mcount = 0;
  1408. }
  1409. rmi4_data->finger[finger].state = finger_status;
  1410. }
  1411. if (touch_count == 0) {
  1412. /* Clear BTN_TOUCH when All touch are released */
  1413. input_report_key(rmi4_data->input_dev,
  1414. BTN_TOUCH, 0);
  1415. #ifndef TYPE_B_PROTOCOL
  1416. input_mt_sync(rmi4_data->input_dev);
  1417. #endif
  1418. }
  1419. input_sync(rmi4_data->input_dev);
  1420. #ifdef TSP_BOOSTER
  1421. if (touch_count)
  1422. synaptics_set_dvfs_lock(rmi4_data, touch_count);
  1423. else
  1424. synaptics_set_dvfs_lock(rmi4_data, 0);
  1425. #endif
  1426. return touch_count;
  1427. }
  1428. static void synaptics_rmi4_f1a_report(struct synaptics_rmi4_data *rmi4_data,
  1429. struct synaptics_rmi4_fn *fhandler)
  1430. {
  1431. int retval;
  1432. unsigned char touch_count = 0;
  1433. unsigned char button;
  1434. unsigned char index;
  1435. unsigned char shift;
  1436. unsigned char status;
  1437. unsigned char *data;
  1438. unsigned short data_addr = fhandler->full_addr.data_base;
  1439. struct synaptics_rmi4_f1a_handle *f1a = fhandler->data;
  1440. static unsigned char do_once = 1;
  1441. static bool current_status[MAX_NUMBER_OF_BUTTONS];
  1442. #ifdef NO_0D_WHILE_2D
  1443. static bool before_2d_status[MAX_NUMBER_OF_BUTTONS];
  1444. static bool while_2d_status[MAX_NUMBER_OF_BUTTONS];
  1445. #endif
  1446. if (do_once) {
  1447. memset(current_status, 0, sizeof(current_status));
  1448. #ifdef NO_0D_WHILE_2D
  1449. memset(before_2d_status, 0, sizeof(before_2d_status));
  1450. memset(while_2d_status, 0, sizeof(while_2d_status));
  1451. #endif
  1452. do_once = 0;
  1453. }
  1454. retval = synaptics_rmi4_i2c_read(rmi4_data,
  1455. data_addr,
  1456. f1a->button_data_buffer,
  1457. f1a->button_bitmask_size);
  1458. if (retval < 0) {
  1459. dev_err(&rmi4_data->i2c_client->dev,
  1460. "%s: Failed to read button data registers\n",
  1461. __func__);
  1462. return;
  1463. }
  1464. data = f1a->button_data_buffer;
  1465. for (button = 0; button < f1a->valid_button_count; button++) {
  1466. index = button / 8;
  1467. shift = button % 8;
  1468. status = ((data[index] >> shift) & MASK_1BIT);
  1469. if (current_status[button] == status)
  1470. continue;
  1471. else
  1472. current_status[button] = status;
  1473. dev_dbg(&rmi4_data->i2c_client->dev,
  1474. "%s: Button %d (code %d) ->%d\n",
  1475. __func__, button,
  1476. f1a->button_map[button],
  1477. status);
  1478. #ifdef NO_0D_WHILE_2D
  1479. if (rmi4_data->fingers_on_2d == false) {
  1480. if (status == 1) {
  1481. before_2d_status[button] = 1;
  1482. } else {
  1483. if (while_2d_status[button] == 1) {
  1484. while_2d_status[button] = 0;
  1485. continue;
  1486. } else {
  1487. before_2d_status[button] = 0;
  1488. }
  1489. }
  1490. touch_count++;
  1491. input_report_key(rmi4_data->input_dev,
  1492. f1a->button_map[button],
  1493. status);
  1494. } else {
  1495. if (before_2d_status[button] == 1) {
  1496. before_2d_status[button] = 0;
  1497. touch_count++;
  1498. input_report_key(rmi4_data->input_dev,
  1499. f1a->button_map[button],
  1500. status);
  1501. } else {
  1502. if (status == 1)
  1503. while_2d_status[button] = 1;
  1504. else
  1505. while_2d_status[button] = 0;
  1506. }
  1507. }
  1508. #else
  1509. touch_count++;
  1510. input_report_key(rmi4_data->input_dev,
  1511. f1a->button_map[button],
  1512. status);
  1513. #endif
  1514. }
  1515. if (touch_count)
  1516. input_sync(rmi4_data->input_dev);
  1517. return;
  1518. }
  1519. #ifdef PROXIMITY
  1520. #ifdef EDGE_SWIPE
  1521. static int synaptics_rmi4_f51_edge_swipe(struct synaptics_rmi4_data *rmi4_data,
  1522. struct synaptics_rmi4_fn *fhandler)
  1523. {
  1524. int retval;
  1525. unsigned short data_base_addr;
  1526. struct synaptics_rmi4_f51_data *data;
  1527. data_base_addr = fhandler->full_addr.data_base;
  1528. data = (struct synaptics_rmi4_f51_data *)fhandler->data;
  1529. retval = synaptics_rmi4_i2c_read(rmi4_data,
  1530. data_base_addr + EDGE_SWIPE_DATA_OFFSET,
  1531. data->edge_swipe_data,
  1532. sizeof(data->edge_swipe_data));
  1533. if (retval < 0)
  1534. return retval;
  1535. if (!f51)
  1536. return -ENODEV;
  1537. if (data->edge_swipe_dg >= 90 && data->edge_swipe_dg <= 180)
  1538. #if defined(CONFIG_MACH_JACTIVESKT)
  1539. f51->surface_data.angle = data->edge_swipe_dg - 90;
  1540. #else
  1541. f51->surface_data.angle = data->edge_swipe_dg - 180;
  1542. #endif
  1543. else if (data->edge_swipe_dg < 90)
  1544. #if defined(CONFIG_MACH_JACTIVESKT)
  1545. f51->surface_data.angle = 90 - data->edge_swipe_dg;
  1546. #else
  1547. f51->surface_data.angle = data->edge_swipe_dg;
  1548. #endif
  1549. else
  1550. dev_err(&rmi4_data->i2c_client->dev, "Skip wrong edge swipe angle [%d]\n",
  1551. data->edge_swipe_dg);
  1552. f51->surface_data.width_major = data->edge_swipe_mm;
  1553. f51->surface_data.wx = data->edge_swipe_wx;
  1554. f51->surface_data.wy = data->edge_swipe_wy;
  1555. f51->surface_data.palm = data->edge_swipe_z;
  1556. dev_dbg(&rmi4_data->i2c_client->dev,
  1557. "%s: edge_data : x[%d], y[%d], z[%d] ,wx[%d], wy[%d], area[%d], angle[%d][%d]\n", __func__,
  1558. data->edge_swipe_x_msb << 8 | data->edge_swipe_x_lsb,
  1559. data->edge_swipe_y_msb << 8 | data->edge_swipe_y_lsb,
  1560. data->edge_swipe_z, data->edge_swipe_wx, data->edge_swipe_wy,
  1561. data->edge_swipe_mm, data->edge_swipe_dg, f51->surface_data.angle);
  1562. return retval;
  1563. }
  1564. #endif
  1565. static void synaptics_rmi4_f51_report(struct synaptics_rmi4_data *rmi4_data,
  1566. struct synaptics_rmi4_fn *fhandler)
  1567. {
  1568. int retval;
  1569. unsigned short data_base_addr;
  1570. int x;
  1571. int y;
  1572. int z;
  1573. struct synaptics_rmi4_f51_data *data;
  1574. #ifdef EDGE_SWIPE
  1575. /* Read edge swipe data */
  1576. if (f51->proximity_controls & HAS_EDGE_SWIPE) {
  1577. retval = synaptics_rmi4_f51_edge_swipe(rmi4_data, fhandler);
  1578. if (retval < 0) {
  1579. dev_err(&rmi4_data->i2c_client->dev,
  1580. "%s: Failed to read edge swipe data\n",
  1581. __func__);
  1582. return;
  1583. }
  1584. }
  1585. #endif
  1586. data_base_addr = fhandler->full_addr.data_base;
  1587. data = (struct synaptics_rmi4_f51_data *)fhandler->data;
  1588. retval = synaptics_rmi4_i2c_read(rmi4_data,
  1589. data_base_addr,
  1590. data->proximity_data,
  1591. sizeof(data->proximity_data));
  1592. if (retval < 0) {
  1593. dev_err(&rmi4_data->i2c_client->dev,
  1594. "%s: Failed to read proximity data registers\n",
  1595. __func__);
  1596. return;
  1597. }
  1598. if (data->proximity_data[0] == 0x00)
  1599. return;
  1600. if (data->finger_hover_det && (data->hover_finger_z > 0)) {
  1601. x = (data->hover_finger_x_4__11 << 4) |
  1602. (data->hover_finger_xy_0__3 & 0x0f);
  1603. y = (data->hover_finger_y_4__11 << 4) |
  1604. (data->hover_finger_xy_0__3 >> 4);
  1605. z = HOVER_Z_MAX - data->hover_finger_z;
  1606. #ifdef TYPE_B_PROTOCOL
  1607. input_mt_slot(rmi4_data->input_dev, 0);
  1608. input_mt_report_slot_state(rmi4_data->input_dev,
  1609. MT_TOOL_FINGER, 1);
  1610. #endif
  1611. input_report_key(rmi4_data->input_dev,
  1612. BTN_TOUCH, 0);
  1613. input_report_key(rmi4_data->input_dev,
  1614. BTN_TOOL_FINGER, 1);
  1615. input_report_abs(rmi4_data->input_dev,
  1616. ABS_MT_POSITION_X, x);
  1617. input_report_abs(rmi4_data->input_dev,
  1618. ABS_MT_POSITION_Y, y);
  1619. input_report_abs(rmi4_data->input_dev,
  1620. ABS_MT_DISTANCE, z);
  1621. #ifndef TYPE_B_PROTOCOL
  1622. input_mt_sync(rmi4_data->input_dev);
  1623. #endif
  1624. input_sync(rmi4_data->input_dev);
  1625. dev_dbg(&rmi4_data->i2c_client->dev,
  1626. "%s: Hover finger:\n"
  1627. "x = %d\n"
  1628. "y = %d\n"
  1629. "z = %d\n",
  1630. __func__, x, y, z);
  1631. rmi4_data->f51_finger = true;
  1632. rmi4_data->fingers_on_2d = false;
  1633. synaptics_rmi4_f51_finger_timer((unsigned long)rmi4_data);
  1634. }
  1635. if (data->air_swipe_det) {
  1636. dev_dbg(&rmi4_data->i2c_client->dev,
  1637. "%s: Swipe direction 0 = %d\n",
  1638. __func__, data->air_swipe_dir_0);
  1639. dev_dbg(&rmi4_data->i2c_client->dev,
  1640. "%s: Swipe direction 1 = %d\n",
  1641. __func__, data->air_swipe_dir_1);
  1642. }
  1643. if (data->large_obj_det) {
  1644. dev_dbg(&rmi4_data->i2c_client->dev,
  1645. "%s: Large object activity = %d\n",
  1646. __func__, data->large_obj_act);
  1647. }
  1648. /*
  1649. if (data->hover_pinch_det) {
  1650. dev_dbg(&rmi4_data->i2c_client->dev,
  1651. "%s: Hover pinch direction = %d\n",
  1652. __func__, data->hover_pinch_dir);
  1653. }
  1654. */
  1655. if (data->object_present) {
  1656. dev_dbg(&rmi4_data->i2c_client->dev,
  1657. "%s: Object presence detected\n",
  1658. __func__);
  1659. }
  1660. return;
  1661. }
  1662. #endif
  1663. /**
  1664. * synaptics_rmi4_report_touch()
  1665. *
  1666. * Called by synaptics_rmi4_sensor_report().
  1667. *
  1668. * This function calls the appropriate finger data reporting function
  1669. * based on the function handler it receives and returns the number of
  1670. * fingers detected.
  1671. */
  1672. static void synaptics_rmi4_report_touch(struct synaptics_rmi4_data *rmi4_data,
  1673. struct synaptics_rmi4_fn *fhandler)
  1674. {
  1675. unsigned char touch_count_2d;
  1676. dev_dbg(&rmi4_data->i2c_client->dev,
  1677. "%s: Function %02x reporting\n",
  1678. __func__, fhandler->fn_number);
  1679. switch (fhandler->fn_number) {
  1680. case SYNAPTICS_RMI4_F11:
  1681. touch_count_2d = synaptics_rmi4_f11_abs_report(rmi4_data,
  1682. fhandler);
  1683. if (touch_count_2d)
  1684. rmi4_data->fingers_on_2d = true;
  1685. else
  1686. rmi4_data->fingers_on_2d = false;
  1687. break;
  1688. case SYNAPTICS_RMI4_F12:
  1689. touch_count_2d = synaptics_rmi4_f12_abs_report(rmi4_data,
  1690. fhandler);
  1691. if (touch_count_2d)
  1692. rmi4_data->fingers_on_2d = true;
  1693. else
  1694. rmi4_data->fingers_on_2d = false;
  1695. break;
  1696. case SYNAPTICS_RMI4_F1A:
  1697. synaptics_rmi4_f1a_report(rmi4_data, fhandler);
  1698. break;
  1699. #ifdef PROXIMITY
  1700. case SYNAPTICS_RMI4_F51:
  1701. synaptics_rmi4_f51_report(rmi4_data, fhandler);
  1702. break;
  1703. #endif
  1704. default:
  1705. break;
  1706. }
  1707. return;
  1708. }
  1709. /**
  1710. * synaptics_rmi4_sensor_report()
  1711. *
  1712. * Called by synaptics_rmi4_irq().
  1713. *
  1714. * This function determines the interrupt source(s) from the sensor
  1715. * and calls synaptics_rmi4_report_touch() with the appropriate
  1716. * function handler for each function with valid data inputs.
  1717. */
  1718. static int synaptics_rmi4_sensor_report(struct synaptics_rmi4_data *rmi4_data)
  1719. {
  1720. int retval;
  1721. unsigned char data[MAX_INTR_REGISTERS + 1];
  1722. unsigned char *intr = &data[1];
  1723. struct synaptics_rmi4_f01_device_status status;
  1724. struct synaptics_rmi4_fn *fhandler;
  1725. struct synaptics_rmi4_exp_fn *exp_fhandler;
  1726. struct synaptics_rmi4_device_info *rmi;
  1727. rmi = &(rmi4_data->rmi4_mod_info);
  1728. /*
  1729. * Get interrupt status information from F01 Data1 register to
  1730. * determine the source(s) that are flagging the interrupt.
  1731. */
  1732. retval = synaptics_rmi4_i2c_read(rmi4_data,
  1733. rmi4_data->f01_data_base_addr,
  1734. data,
  1735. rmi4_data->num_of_intr_regs + 1);
  1736. if (retval < 0) {
  1737. dev_err(&rmi4_data->i2c_client->dev,
  1738. "%s: Failed to read interrupt status\n",
  1739. __func__);
  1740. return retval;
  1741. }
  1742. status.data[0] = data[0];
  1743. if (status.unconfigured) {
  1744. if (rmi4_data->doing_reflash) {
  1745. dev_err(&rmi4_data->i2c_client->dev,
  1746. "Spontaneous reset detected during reflash.\n");
  1747. return 0;
  1748. }
  1749. dev_info(&rmi4_data->i2c_client->dev,
  1750. "Spontaneous reset detected\n");
  1751. retval = synaptics_rmi4_reinit_device(rmi4_data);
  1752. if (retval < 0) {
  1753. dev_err(&rmi4_data->i2c_client->dev,
  1754. "%s: Failed to reinit device\n",
  1755. __func__);
  1756. }
  1757. return 0;
  1758. }
  1759. /*
  1760. * Traverse the function handler list and service the source(s)
  1761. * of the interrupt accordingly.
  1762. */
  1763. if (!list_empty(&rmi->support_fn_list)) {
  1764. list_for_each_entry(fhandler, &rmi->support_fn_list, link) {
  1765. if (fhandler->num_of_data_sources) {
  1766. if (fhandler->intr_mask &
  1767. intr[fhandler->intr_reg_num]) {
  1768. synaptics_rmi4_report_touch(rmi4_data,
  1769. fhandler);
  1770. }
  1771. }
  1772. }
  1773. }
  1774. if (!list_empty(&exp_fn_list)) {
  1775. list_for_each_entry(exp_fhandler, &exp_fn_list, link) {
  1776. if (exp_fhandler->func_attn != NULL)
  1777. exp_fhandler->func_attn(rmi4_data, intr[0]);
  1778. }
  1779. }
  1780. return 0;
  1781. }
  1782. /**
  1783. * synaptics_rmi4_irq()
  1784. *
  1785. * Called by the kernel when an interrupt occurs (when the sensor
  1786. * asserts the attention irq).
  1787. *
  1788. * This function is the ISR thread and handles the acquisition
  1789. * and the reporting of finger data when the presence of fingers
  1790. * is detected.
  1791. */
  1792. static irqreturn_t synaptics_rmi4_irq(int irq, void *data)
  1793. {
  1794. int retval;
  1795. struct synaptics_rmi4_data *rmi4_data = data;
  1796. do {
  1797. retval = synaptics_rmi4_sensor_report(rmi4_data);
  1798. if (retval < 0) {
  1799. dev_err(&rmi4_data->i2c_client->dev, "%s: Failed to read",
  1800. __func__);
  1801. goto out;
  1802. }
  1803. if (!rmi4_data->touch_stopped)
  1804. goto out;
  1805. } while (!gpio_get_value(rmi4_data->irq));
  1806. out:
  1807. return IRQ_HANDLED;
  1808. }
  1809. /**
  1810. * synaptics_rmi4_irq_enable()
  1811. *
  1812. * Called by synaptics_rmi4_probe() and the power management functions
  1813. * in this driver and also exported to other expansion Function modules
  1814. * such as rmi_dev.
  1815. *
  1816. * This function handles the enabling and disabling of the attention
  1817. * irq including the setting up of the ISR thread.
  1818. */
  1819. static int synaptics_rmi4_irq_enable(struct synaptics_rmi4_data *rmi4_data,
  1820. bool enable)
  1821. {
  1822. int retval = 0;
  1823. unsigned char intr_status;
  1824. if (enable) {
  1825. if (rmi4_data->irq_enabled)
  1826. return retval;
  1827. /* Clear interrupts first */
  1828. retval = synaptics_rmi4_i2c_read(rmi4_data,
  1829. rmi4_data->f01_data_base_addr + 1,
  1830. &intr_status,
  1831. rmi4_data->num_of_intr_regs);
  1832. if (retval < 0)
  1833. return retval;
  1834. retval = request_threaded_irq(rmi4_data->irq, NULL,
  1835. synaptics_rmi4_irq, IRQF_TRIGGER_FALLING,
  1836. DRIVER_NAME, rmi4_data);
  1837. if (retval < 0) {
  1838. dev_err(&rmi4_data->i2c_client->dev,
  1839. "%s: Failed to create irq thread\n",
  1840. __func__);
  1841. return retval;
  1842. }
  1843. rmi4_data->irq_enabled = true;
  1844. } else {
  1845. if (rmi4_data->irq_enabled) {
  1846. disable_irq(rmi4_data->irq);
  1847. free_irq(rmi4_data->irq, rmi4_data);
  1848. rmi4_data->irq_enabled = false;
  1849. }
  1850. }
  1851. return retval;
  1852. }
  1853. /**
  1854. * synaptics_rmi4_f11_init()
  1855. *
  1856. * Called by synaptics_rmi4_query_device().
  1857. *
  1858. * This funtion parses information from the Function 11 registers
  1859. * and determines the number of fingers supported, x and y data ranges,
  1860. * offset to the associated interrupt status register, interrupt bit
  1861. * mask, and gathers finger data acquisition capabilities from the query
  1862. * registers.
  1863. */
  1864. static int synaptics_rmi4_f11_init(struct synaptics_rmi4_data *rmi4_data,
  1865. struct synaptics_rmi4_fn *fhandler,
  1866. struct synaptics_rmi4_fn_desc *fd,
  1867. unsigned int intr_count)
  1868. {
  1869. int retval;
  1870. unsigned char ii;
  1871. unsigned char intr_offset;
  1872. unsigned char abs_data_size;
  1873. unsigned char abs_data_blk_size;
  1874. unsigned char query[F11_STD_QUERY_LEN];
  1875. unsigned char control[F11_STD_CTRL_LEN];
  1876. fhandler->fn_number = fd->fn_number;
  1877. fhandler->num_of_data_sources = fd->intr_src_count;
  1878. retval = synaptics_rmi4_i2c_read(rmi4_data,
  1879. fhandler->full_addr.query_base,
  1880. query,
  1881. sizeof(query));
  1882. if (retval < 0)
  1883. return retval;
  1884. /* Maximum number of fingers supported */
  1885. if ((query[1] & MASK_3BIT) <= 4)
  1886. fhandler->num_of_data_points = (query[1] & MASK_3BIT) + 1;
  1887. else if ((query[1] & MASK_3BIT) == 5)
  1888. fhandler->num_of_data_points = 10;
  1889. rmi4_data->num_of_fingers = fhandler->num_of_data_points;
  1890. retval = synaptics_rmi4_i2c_read(rmi4_data,
  1891. fhandler->full_addr.ctrl_base,
  1892. control,
  1893. sizeof(control));
  1894. if (retval < 0)
  1895. return retval;
  1896. /* Maximum x and y */
  1897. rmi4_data->sensor_max_x = ((control[6] & MASK_8BIT) << 0) |
  1898. ((control[7] & MASK_4BIT) << 8);
  1899. rmi4_data->sensor_max_y = ((control[8] & MASK_8BIT) << 0) |
  1900. ((control[9] & MASK_4BIT) << 8);
  1901. dev_dbg(&rmi4_data->i2c_client->dev,
  1902. "%s: Function %02x max x = %d max y = %d\n",
  1903. __func__, fhandler->fn_number,
  1904. rmi4_data->sensor_max_x,
  1905. rmi4_data->sensor_max_y);
  1906. rmi4_data->max_touch_width = MAX_F11_TOUCH_WIDTH;
  1907. fhandler->intr_reg_num = (intr_count + 7) / 8;
  1908. if (fhandler->intr_reg_num != 0)
  1909. fhandler->intr_reg_num -= 1;
  1910. /* Set an enable bit for each data source */
  1911. intr_offset = intr_count % 8;
  1912. fhandler->intr_mask = 0;
  1913. for (ii = intr_offset;
  1914. ii < ((fd->intr_src_count & MASK_3BIT) +
  1915. intr_offset);
  1916. ii++)
  1917. fhandler->intr_mask |= 1 << ii;
  1918. abs_data_size = query[5] & MASK_2BIT;
  1919. abs_data_blk_size = 3 + (2 * (abs_data_size == 0 ? 1 : 0));
  1920. fhandler->size_of_data_register_block = abs_data_blk_size;
  1921. fhandler->data = NULL;
  1922. return retval;
  1923. }
  1924. #ifdef CONFIG_GLOVE_TOUCH
  1925. int synaptics_rmi4_glove_mode_enables(struct synaptics_rmi4_data *rmi4_data)
  1926. {
  1927. int retval;
  1928. if (GLOVE_FEATURE_EN != rmi4_data->glove_mode_feature) {
  1929. dev_err(&rmi4_data->i2c_client->dev,
  1930. "%s: Ver[%02X%02X%02X] FW does not support glove mode %02X\n",
  1931. __func__, rmi4_data->panel_revision, rmi4_data->ic_revision_of_ic,
  1932. rmi4_data->fw_version_of_ic, rmi4_data->glove_mode_feature);
  1933. return 0;
  1934. }
  1935. if (rmi4_data->touch_stopped)
  1936. return 0;
  1937. dev_info(&rmi4_data->i2c_client->dev, "%s: [%02X]: %s\n",
  1938. __func__, rmi4_data->glove_mode_enables,
  1939. (rmi4_data->glove_mode_enables == 0x07) ? "fast glove & clear cover enable" :
  1940. (rmi4_data->glove_mode_enables == 0x06) ? "fast glove & flip cover enable" :
  1941. (rmi4_data->glove_mode_enables == 0x05) ? "only fast glove enable" :
  1942. (rmi4_data->glove_mode_enables == 0x03) ? "only clear cover enable" :
  1943. (rmi4_data->glove_mode_enables == 0x02) ? "only flip cover enable" :
  1944. (rmi4_data->glove_mode_enables == 0x01) ? "only glove enable" : "glove disable");
  1945. retval = synaptics_rmi4_i2c_write(rmi4_data,
  1946. rmi4_data->glove_mode_enables_addr,
  1947. &rmi4_data->glove_mode_enables,
  1948. sizeof(rmi4_data->glove_mode_enables));
  1949. if (retval < 0)
  1950. return retval;
  1951. return 0;
  1952. }
  1953. #endif
  1954. static int synaptics_rmi4_f12_set_enables(struct synaptics_rmi4_data *rmi4_data,
  1955. unsigned short address)
  1956. {
  1957. int retval;
  1958. unsigned char enable_mask;
  1959. static unsigned short ctrl_28_address;
  1960. if (address)
  1961. ctrl_28_address = address;
  1962. enable_mask = RPT_DEFAULT;
  1963. #ifdef REPORT_2D_Z
  1964. enable_mask |= RPT_Z;
  1965. #endif
  1966. #ifdef REPORT_2D_W
  1967. enable_mask |= (RPT_WX | RPT_WY);
  1968. #endif
  1969. retval = synaptics_rmi4_i2c_write(rmi4_data,
  1970. ctrl_28_address,
  1971. &enable_mask,
  1972. sizeof(enable_mask));
  1973. if (retval < 0)
  1974. return retval;
  1975. return retval;
  1976. }
  1977. /**
  1978. * synaptics_rmi4_f12_init()
  1979. *
  1980. * Called by synaptics_rmi4_query_device().
  1981. *
  1982. * This funtion parses information from the Function 12 registers and
  1983. * determines the number of fingers supported, offset to the data1
  1984. * register, x and y data ranges, offset to the associated interrupt
  1985. * status register, interrupt bit mask, and allocates memory resources
  1986. * for finger data acquisition.
  1987. */
  1988. static int synaptics_rmi4_f12_init(struct synaptics_rmi4_data *rmi4_data,
  1989. struct synaptics_rmi4_fn *fhandler,
  1990. struct synaptics_rmi4_fn_desc *fd,
  1991. unsigned int intr_count)
  1992. {
  1993. int retval;
  1994. unsigned char ii;
  1995. unsigned char intr_offset;
  1996. unsigned char size_of_2d_data;
  1997. unsigned char ctrl_8_offset;
  1998. unsigned char ctrl_9_offset;
  1999. unsigned char ctrl_23_offset;
  2000. unsigned char ctrl_26_offset;
  2001. unsigned char ctrl_28_offset;
  2002. unsigned char fingers_to_support = F12_FINGERS_TO_SUPPORT;
  2003. struct synaptics_rmi4_f12_query_5 query_5;
  2004. struct synaptics_rmi4_f12_query_8 query_8;
  2005. struct synaptics_rmi4_f12_ctrl_8 ctrl_8;
  2006. struct synaptics_rmi4_f12_ctrl_9 ctrl_9;
  2007. struct synaptics_rmi4_f12_ctrl_23 ctrl_23;
  2008. #ifdef CONFIG_GLOVE_TOUCH
  2009. struct synaptics_rmi4_f12_ctrl_26 ctrl_26;
  2010. #endif
  2011. fhandler->fn_number = fd->fn_number;
  2012. fhandler->num_of_data_sources = fd->intr_src_count;
  2013. retval = synaptics_rmi4_i2c_read(rmi4_data,
  2014. fhandler->full_addr.query_base + 5,
  2015. query_5.data,
  2016. sizeof(query_5.data));
  2017. if (retval < 0)
  2018. return retval;
  2019. ctrl_8_offset = query_5.ctrl0_is_present +
  2020. query_5.ctrl1_is_present +
  2021. query_5.ctrl2_is_present +
  2022. query_5.ctrl3_is_present +
  2023. query_5.ctrl4_is_present +
  2024. query_5.ctrl5_is_present +
  2025. query_5.ctrl6_is_present +
  2026. query_5.ctrl7_is_present;
  2027. ctrl_9_offset = ctrl_8_offset +
  2028. query_5.ctrl8_is_present;
  2029. ctrl_23_offset = ctrl_9_offset +
  2030. query_5.ctrl9_is_present +
  2031. query_5.ctrl10_is_present +
  2032. query_5.ctrl11_is_present +
  2033. query_5.ctrl12_is_present +
  2034. query_5.ctrl13_is_present +
  2035. query_5.ctrl14_is_present +
  2036. query_5.ctrl15_is_present +
  2037. query_5.ctrl16_is_present +
  2038. query_5.ctrl17_is_present +
  2039. query_5.ctrl18_is_present +
  2040. query_5.ctrl19_is_present +
  2041. query_5.ctrl20_is_present +
  2042. query_5.ctrl21_is_present +
  2043. query_5.ctrl22_is_present;
  2044. ctrl_26_offset = ctrl_23_offset +
  2045. query_5.ctrl23_is_present +
  2046. query_5.ctrl24_is_present +
  2047. query_5.ctrl25_is_present;
  2048. ctrl_28_offset = ctrl_26_offset +
  2049. query_5.ctrl26_is_present +
  2050. query_5.ctrl27_is_present;
  2051. retval = synaptics_rmi4_i2c_read(rmi4_data,
  2052. fhandler->full_addr.ctrl_base + ctrl_23_offset,
  2053. ctrl_23.data,
  2054. sizeof(ctrl_23.data));
  2055. if (retval < 0)
  2056. return retval;
  2057. /* Maximum number of fingers supported */
  2058. fhandler->num_of_data_points = min(ctrl_23.max_reported_objects,
  2059. fingers_to_support);
  2060. rmi4_data->num_of_fingers = fhandler->num_of_data_points;
  2061. retval = synaptics_rmi4_f12_set_enables(rmi4_data,
  2062. fhandler->full_addr.ctrl_base + ctrl_28_offset);
  2063. if (retval < 0)
  2064. return retval;
  2065. retval = synaptics_rmi4_i2c_read(rmi4_data,
  2066. fhandler->full_addr.query_base + 8,
  2067. query_8.data,
  2068. sizeof(query_8.data));
  2069. if (retval < 0)
  2070. return retval;
  2071. /* Determine the presence of the Data0 register */
  2072. fhandler->data1_offset = query_8.data0_is_present;
  2073. retval = synaptics_rmi4_i2c_read(rmi4_data,
  2074. fhandler->full_addr.ctrl_base + ctrl_8_offset,
  2075. ctrl_8.data,
  2076. sizeof(ctrl_8.data));
  2077. if (retval < 0)
  2078. return retval;
  2079. /* Maximum x and y */
  2080. rmi4_data->sensor_max_x =
  2081. ((unsigned short)ctrl_8.max_x_coord_lsb << 0) |
  2082. ((unsigned short)ctrl_8.max_x_coord_msb << 8);
  2083. rmi4_data->sensor_max_y =
  2084. ((unsigned short)ctrl_8.max_y_coord_lsb << 0) |
  2085. ((unsigned short)ctrl_8.max_y_coord_msb << 8);
  2086. dev_dbg(&rmi4_data->i2c_client->dev,
  2087. "%s: Function %02x max x = %d max y = %d\n",
  2088. __func__, fhandler->fn_number,
  2089. rmi4_data->sensor_max_x,
  2090. rmi4_data->sensor_max_y);
  2091. if (!rmi4_data->board->num_of_rx && !rmi4_data->board->num_of_tx) {
  2092. rmi4_data->num_of_rx = ctrl_8.num_of_rx;
  2093. rmi4_data->num_of_tx = ctrl_8.num_of_tx;
  2094. rmi4_data->max_touch_width = max(rmi4_data->num_of_rx,
  2095. rmi4_data->num_of_tx);
  2096. rmi4_data->num_of_node = ctrl_8.num_of_rx * ctrl_8.num_of_tx;
  2097. } else {
  2098. rmi4_data->num_of_rx = rmi4_data->board->num_of_rx;
  2099. rmi4_data->num_of_tx = rmi4_data->board->num_of_tx;
  2100. rmi4_data->max_touch_width = max(rmi4_data->num_of_rx,
  2101. rmi4_data->num_of_tx);
  2102. rmi4_data->num_of_node = rmi4_data->num_of_rx * rmi4_data->num_of_tx;
  2103. }
  2104. retval = synaptics_rmi4_i2c_read(rmi4_data,
  2105. fhandler->full_addr.ctrl_base + ctrl_9_offset,
  2106. ctrl_9.data,
  2107. sizeof(ctrl_9.data));
  2108. if (retval < 0)
  2109. return retval;
  2110. rmi4_data->touch_threshold = (int)ctrl_9.touch_threshold;
  2111. rmi4_data->gloved_sensitivity = (int)ctrl_9.gloved_finger;
  2112. dev_info(&rmi4_data->i2c_client->dev,
  2113. "%s: %02x num_Rx:%d num_Tx:%d, node:%d, threshold:%d, gloved sensitivity:%x\n",
  2114. __func__, fhandler->fn_number,
  2115. rmi4_data->num_of_rx, rmi4_data->num_of_tx,
  2116. rmi4_data->num_of_node, rmi4_data->touch_threshold,
  2117. rmi4_data->gloved_sensitivity);
  2118. fhandler->intr_reg_num = (intr_count + 7) / 8;
  2119. if (fhandler->intr_reg_num != 0)
  2120. fhandler->intr_reg_num -= 1;
  2121. /* Set an enable bit for each data source */
  2122. intr_offset = intr_count % 8;
  2123. fhandler->intr_mask = 0;
  2124. for (ii = intr_offset;
  2125. ii < ((fd->intr_src_count & MASK_3BIT) +
  2126. intr_offset);
  2127. ii++)
  2128. fhandler->intr_mask |= 1 << ii;
  2129. size_of_2d_data = sizeof(struct synaptics_rmi4_f12_finger_data);
  2130. /* Allocate memory for finger data storage space */
  2131. fhandler->data_size = fhandler->num_of_data_points * size_of_2d_data;
  2132. fhandler->data = kzalloc(fhandler->data_size, GFP_KERNEL);
  2133. #ifdef CONFIG_GLOVE_TOUCH
  2134. rmi4_data->glove_mode_enables_addr = fhandler->full_addr.ctrl_base +
  2135. ctrl_26_offset;
  2136. retval = synaptics_rmi4_i2c_read(rmi4_data,
  2137. fhandler->full_addr.query_base + 10,
  2138. ctrl_26.data,
  2139. sizeof(ctrl_26.data));
  2140. if (retval < 0)
  2141. return retval;
  2142. rmi4_data->glove_mode_feature = ctrl_26.glove_feature_enable;
  2143. synaptics_rmi4_glove_mode_enables(rmi4_data);
  2144. #endif
  2145. return retval;
  2146. }
  2147. static int synaptics_rmi4_f1a_alloc_mem(struct synaptics_rmi4_data *rmi4_data,
  2148. struct synaptics_rmi4_fn *fhandler)
  2149. {
  2150. int retval;
  2151. struct synaptics_rmi4_f1a_handle *f1a;
  2152. f1a = kzalloc(sizeof(*f1a), GFP_KERNEL);
  2153. if (!f1a) {
  2154. dev_err(&rmi4_data->i2c_client->dev,
  2155. "%s: Failed to alloc mem for function handle\n",
  2156. __func__);
  2157. return -ENOMEM;
  2158. }
  2159. fhandler->data = (void *)f1a;
  2160. retval = synaptics_rmi4_i2c_read(rmi4_data,
  2161. fhandler->full_addr.query_base,
  2162. f1a->button_query.data,
  2163. sizeof(f1a->button_query.data));
  2164. if (retval < 0) {
  2165. dev_err(&rmi4_data->i2c_client->dev,
  2166. "%s: Failed to read query registers\n",
  2167. __func__);
  2168. return retval;
  2169. }
  2170. f1a->button_count = f1a->button_query.max_button_count + 1;
  2171. f1a->button_bitmask_size = (f1a->button_count + 7) / 8;
  2172. f1a->button_data_buffer = kcalloc(f1a->button_bitmask_size,
  2173. sizeof(*(f1a->button_data_buffer)), GFP_KERNEL);
  2174. if (!f1a->button_data_buffer) {
  2175. dev_err(&rmi4_data->i2c_client->dev,
  2176. "%s: Failed to alloc mem for data buffer\n",
  2177. __func__);
  2178. return -ENOMEM;
  2179. }
  2180. f1a->button_map = kcalloc(f1a->button_count,
  2181. sizeof(*(f1a->button_map)), GFP_KERNEL);
  2182. if (!f1a->button_map) {
  2183. dev_err(&rmi4_data->i2c_client->dev,
  2184. "%s: Failed to alloc mem for button map\n",
  2185. __func__);
  2186. return -ENOMEM;
  2187. }
  2188. return 0;
  2189. }
  2190. static int synaptics_rmi4_f1a_button_map(struct synaptics_rmi4_data *rmi4_data,
  2191. struct synaptics_rmi4_fn *fhandler)
  2192. {
  2193. unsigned char ii;
  2194. struct synaptics_rmi4_f1a_handle *f1a = fhandler->data;
  2195. const struct synaptics_rmi4_platform_data *pdata = rmi4_data->board;
  2196. if (!pdata->f1a_button_map) {
  2197. dev_err(&rmi4_data->i2c_client->dev,
  2198. "%s: f1a_button_map is NULL in board file\n",
  2199. __func__);
  2200. return -ENODEV;
  2201. } else if (!pdata->f1a_button_map->map) {
  2202. dev_err(&rmi4_data->i2c_client->dev,
  2203. "%s: Button map is missing in board file\n",
  2204. __func__);
  2205. return -ENODEV;
  2206. } else {
  2207. if (pdata->f1a_button_map->nbuttons != f1a->button_count) {
  2208. f1a->valid_button_count = min(f1a->button_count,
  2209. pdata->f1a_button_map->nbuttons);
  2210. } else {
  2211. f1a->valid_button_count = f1a->button_count;
  2212. }
  2213. for (ii = 0; ii < f1a->valid_button_count; ii++)
  2214. f1a->button_map[ii] = pdata->f1a_button_map->map[ii];
  2215. }
  2216. return 0;
  2217. }
  2218. static void synaptics_rmi4_f1a_kfree(struct synaptics_rmi4_fn *fhandler)
  2219. {
  2220. struct synaptics_rmi4_f1a_handle *f1a = fhandler->data;
  2221. if (f1a) {
  2222. kfree(f1a->button_data_buffer);
  2223. kfree(f1a->button_map);
  2224. kfree(f1a);
  2225. fhandler->data = NULL;
  2226. }
  2227. return;
  2228. }
  2229. static int synaptics_rmi4_f1a_init(struct synaptics_rmi4_data *rmi4_data,
  2230. struct synaptics_rmi4_fn *fhandler,
  2231. struct synaptics_rmi4_fn_desc *fd,
  2232. unsigned int intr_count)
  2233. {
  2234. int retval;
  2235. unsigned char ii;
  2236. unsigned short intr_offset;
  2237. fhandler->fn_number = fd->fn_number;
  2238. fhandler->num_of_data_sources = fd->intr_src_count;
  2239. fhandler->intr_reg_num = (intr_count + 7) / 8;
  2240. if (fhandler->intr_reg_num != 0)
  2241. fhandler->intr_reg_num -= 1;
  2242. /* Set an enable bit for each data source */
  2243. intr_offset = intr_count % 8;
  2244. fhandler->intr_mask = 0;
  2245. for (ii = intr_offset;
  2246. ii < ((fd->intr_src_count & MASK_3BIT) +
  2247. intr_offset);
  2248. ii++)
  2249. fhandler->intr_mask |= 1 << ii;
  2250. retval = synaptics_rmi4_f1a_alloc_mem(rmi4_data, fhandler);
  2251. if (retval < 0)
  2252. goto error_exit;
  2253. retval = synaptics_rmi4_f1a_button_map(rmi4_data, fhandler);
  2254. if (retval < 0)
  2255. goto error_exit;
  2256. rmi4_data->button_0d_enabled = 1;
  2257. return 0;
  2258. error_exit:
  2259. synaptics_rmi4_f1a_kfree(fhandler);
  2260. return retval;
  2261. }
  2262. static int synaptics_rmi4_f34_read_version(struct synaptics_rmi4_data *rmi4_data,
  2263. struct synaptics_rmi4_fn *fhandler)
  2264. {
  2265. int retval;
  2266. struct synaptics_rmi4_f34_ctrl_3 ctrl_3;
  2267. retval = synaptics_rmi4_i2c_read(rmi4_data,
  2268. fhandler->full_addr.ctrl_base,
  2269. ctrl_3.data,
  2270. sizeof(ctrl_3.data));
  2271. if (retval < 0)
  2272. return retval;
  2273. dev_info(&rmi4_data->i2c_client->dev, "%s: [IC] [date, revision, version, panel] [%02d/%02d, 0x%02X, 0x%02X, 0x%02X]\n",
  2274. __func__, ctrl_3.fw_release_month, ctrl_3.fw_release_date,
  2275. ctrl_3.fw_release_revision, ctrl_3.fw_release_version,
  2276. rmi4_data->panel_revision);
  2277. rmi4_data->fw_release_date_of_ic =
  2278. (ctrl_3.fw_release_month << 8) | ctrl_3.fw_release_date;
  2279. rmi4_data->ic_revision_of_ic = ctrl_3.fw_release_revision;
  2280. rmi4_data->fw_version_of_ic = ctrl_3.fw_release_version;
  2281. return retval;
  2282. }
  2283. static int synaptics_rmi4_f34_init(struct synaptics_rmi4_data *rmi4_data,
  2284. struct synaptics_rmi4_fn *fhandler,
  2285. struct synaptics_rmi4_fn_desc *fd,
  2286. unsigned int intr_count)
  2287. {
  2288. int retval;
  2289. fhandler->fn_number = fd->fn_number;
  2290. fhandler->num_of_data_sources = fd->intr_src_count;
  2291. retval = synaptics_rmi4_f34_read_version(rmi4_data, fhandler);
  2292. if (retval < 0)
  2293. return retval;
  2294. fhandler->data = NULL;
  2295. return retval;
  2296. }
  2297. #ifdef PROXIMITY
  2298. #ifdef USE_CUSTOM_REZERO
  2299. static int synaptics_rmi4_f51_set_custom_rezero(struct synaptics_rmi4_data *rmi4_data)
  2300. {
  2301. int retval;
  2302. unsigned char custom_rezero;
  2303. retval = synaptics_rmi4_i2c_read(rmi4_data,
  2304. f51->proximity_custom_rezero_addr,
  2305. &custom_rezero, sizeof(custom_rezero));
  2306. if (F51_VERSION == f51->num_of_data_sources)
  2307. custom_rezero |= 0x34;
  2308. else
  2309. custom_rezero |= 0x01;
  2310. retval = synaptics_rmi4_i2c_write(rmi4_data,
  2311. f51->proximity_custom_rezero_addr,
  2312. &custom_rezero, sizeof(custom_rezero));
  2313. if (retval < 0) {
  2314. dev_err(&rmi4_data->i2c_client->dev, "%s: fail to write custom rezero\n",
  2315. __func__);
  2316. return retval;
  2317. }
  2318. dev_info(&rmi4_data->i2c_client->dev, "%s\n", __func__);
  2319. return 0;
  2320. }
  2321. static void synaptics_rmi4_rezero_work(struct work_struct *work)
  2322. {
  2323. int retval;
  2324. struct synaptics_rmi4_data *rmi4_data =
  2325. container_of(work, struct synaptics_rmi4_data,
  2326. rezero_work.work);
  2327. /* Do not check hover enable status, because rezero bit does not effect
  2328. * to doze(mutual only) mdoe.
  2329. */
  2330. retval = synaptics_rmi4_f51_set_custom_rezero(rmi4_data);
  2331. if (retval < 0)
  2332. dev_err(&rmi4_data->i2c_client->dev,
  2333. "%s: Failed to rezero device\n", __func__);
  2334. }
  2335. #endif
  2336. int synaptics_proximity_no_sleep_set(bool enables)
  2337. {
  2338. int retval;
  2339. unsigned char no_sleep = 0;
  2340. if (!f51)
  2341. return -ENODEV;
  2342. retval = synaptics_rmi4_i2c_read(f51->rmi4_data,
  2343. f51->rmi4_data->f01_ctrl_base_addr,
  2344. &no_sleep,
  2345. sizeof(no_sleep));
  2346. if (retval <= 0)
  2347. dev_err(&f51->rmi4_data->i2c_client->dev, "%s: fail to read no_sleep[ret:%d]\n",
  2348. __func__, retval);
  2349. if (enables)
  2350. no_sleep |= NO_SLEEP_ON;
  2351. else
  2352. no_sleep &= ~(NO_SLEEP_ON);
  2353. retval = synaptics_rmi4_i2c_write(f51->rmi4_data,
  2354. f51->rmi4_data->f01_ctrl_base_addr,
  2355. &no_sleep,
  2356. sizeof(no_sleep));
  2357. if (retval <= 0)
  2358. dev_err(&f51->rmi4_data->i2c_client->dev, "%s: fail to set no_sleep[%X][ret:%d]\n",
  2359. __func__, no_sleep, retval);
  2360. return retval;
  2361. }
  2362. EXPORT_SYMBOL(synaptics_proximity_no_sleep_set);
  2363. static int synaptics_rmi4_f51_set_enables(struct synaptics_rmi4_data *rmi4_data)
  2364. {
  2365. int retval;
  2366. dev_info(&rmi4_data->i2c_client->dev, "%s: %s[0x%x]\n", __func__,
  2367. (f51->proximity_enables & FINGER_HOVER_EN) ? "enable" : "disable", f51->proximity_enables);
  2368. retval = synaptics_rmi4_i2c_write(rmi4_data,
  2369. f51->proximity_enables_addr,
  2370. &f51->proximity_enables,
  2371. sizeof(f51->proximity_enables));
  2372. if (retval < 0)
  2373. return retval;
  2374. return 0;
  2375. }
  2376. static int synaptics_rmi4_f51_set_init(struct synaptics_rmi4_data *rmi4_data)
  2377. {
  2378. int retval;
  2379. dev_info(&rmi4_data->i2c_client->dev, "%s: proximity controls:[0X%02X]\n",
  2380. __func__, f51->proximity_controls);
  2381. #ifdef USE_CUSTOM_REZERO
  2382. retval = synaptics_rmi4_f51_set_custom_rezero(rmi4_data);
  2383. if (retval < 0)
  2384. return retval;
  2385. /*
  2386. * Need 100msec to finish acquiring for hover baseline
  2387. * Synaptics recommend that do not send a hover disable cmd during 100msec.
  2388. * (after send custom rezero cmd on IC on time)
  2389. * Under current driver, this delay does not affect to wakeup latency.
  2390. * But it will affect to latency, below proximity enable code can move into delay work.
  2391. */
  2392. msleep(SYNAPTICS_REZERO_TIME);
  2393. #endif
  2394. retval = synaptics_rmi4_f51_set_enables(rmi4_data);
  2395. if (retval < 0) {
  2396. dev_err(&rmi4_data->i2c_client->dev,
  2397. "%s: Failed to set enable\n", __func__);
  2398. }
  2399. return retval;
  2400. }
  2401. static int synaptics_rmi4_f51_init(struct synaptics_rmi4_data *rmi4_data,
  2402. struct synaptics_rmi4_fn *fhandler,
  2403. struct synaptics_rmi4_fn_desc *fd,
  2404. unsigned int intr_count)
  2405. {
  2406. int retval;
  2407. unsigned char ii;
  2408. unsigned short intr_offset;
  2409. struct synaptics_rmi4_f51_data *data_register;
  2410. struct synaptics_rmi4_f51_query query_register;
  2411. fhandler->fn_number = fd->fn_number;
  2412. fhandler->num_of_data_sources = fd->intr_src_count;
  2413. fhandler->intr_reg_num = (intr_count + 7) / 8;
  2414. if (fhandler->intr_reg_num != 0)
  2415. fhandler->intr_reg_num -= 1;
  2416. /* Set an enable bit for each data source */
  2417. intr_offset = intr_count % 8;
  2418. fhandler->intr_mask = 0;
  2419. for (ii = intr_offset;
  2420. ii < ((fd->intr_src_count & MASK_3BIT) + intr_offset);
  2421. ii++)
  2422. fhandler->intr_mask |= 1 << ii;
  2423. fhandler->data_size = sizeof(*data_register);
  2424. data_register = kzalloc(fhandler->data_size, GFP_KERNEL);
  2425. fhandler->data = (void *)data_register;
  2426. f51 = kzalloc(sizeof(*f51), GFP_KERNEL);
  2427. f51->rmi4_data = rmi4_data;
  2428. if (F51_VERSION == fhandler->num_of_data_sources) {
  2429. f51->num_of_data_sources = fhandler->num_of_data_sources;
  2430. f51->proximity_enables = AIR_SWIPE_EN | SLEEP_PROXIMITY;
  2431. f51->proximity_enables_addr = fhandler->full_addr.ctrl_base +
  2432. F51_PROXIMITY_ENABLES_OFFSET;
  2433. #ifdef USE_CUSTOM_REZERO
  2434. f51->proximity_custom_rezero_addr = fhandler->full_addr.ctrl_base +
  2435. F51_GENERAL_CONTROL_OFFSET;
  2436. #endif
  2437. } else {
  2438. f51->proximity_enables = PROXIMITY_DEFAULT;
  2439. f51->proximity_enables_addr = fhandler->full_addr.ctrl_base +
  2440. F51_CTRL54_OFFSET;
  2441. #ifdef USE_CUSTOM_REZERO
  2442. f51->proximity_custom_rezero_addr = fhandler->full_addr.ctrl_base +
  2443. F51_CTRL78_OFFSET;
  2444. #endif
  2445. }
  2446. retval = synaptics_rmi4_i2c_read(rmi4_data,
  2447. fhandler->full_addr.query_base,
  2448. query_register.data,
  2449. sizeof(query_register));
  2450. if (retval < 0)
  2451. return retval;
  2452. /* Save proximity controls(query 4 register) to get which functions
  2453. * are supported by firmware.
  2454. */
  2455. f51->proximity_controls = query_register.proximity_controls;
  2456. retval = synaptics_rmi4_f51_set_init(rmi4_data);
  2457. if (retval < 0) {
  2458. dev_err(&rmi4_data->i2c_client->dev, "%s: fail proximity set init\n",
  2459. __func__);
  2460. return retval;
  2461. }
  2462. return 0;
  2463. }
  2464. int synaptics_rmi4_proximity_enables(unsigned char enables)
  2465. {
  2466. int retval;
  2467. if (!f51)
  2468. return -ENODEV;
  2469. if (F51_VERSION == f51->num_of_data_sources) {
  2470. if (enables)
  2471. f51->proximity_enables = AIR_SWIPE_EN | FINGER_HOVER_EN;
  2472. else
  2473. f51->proximity_enables = AIR_SWIPE_EN | SLEEP_PROXIMITY;
  2474. } else {
  2475. if (enables)
  2476. f51->proximity_enables = PROXIMITY_ENABLE;
  2477. else
  2478. f51->proximity_enables = PROXIMITY_DEFAULT;
  2479. }
  2480. if (f51->rmi4_data->touch_stopped)
  2481. return 0;
  2482. retval = synaptics_rmi4_f51_set_enables(f51->rmi4_data);
  2483. if (retval < 0)
  2484. return retval;
  2485. #ifdef USE_CUSTOM_REZERO
  2486. cancel_delayed_work(&f51->rmi4_data->rezero_work);
  2487. if (f51->proximity_enables & FINGER_HOVER_EN)
  2488. schedule_delayed_work(&f51->rmi4_data->rezero_work,
  2489. msecs_to_jiffies(SYNAPTICS_REZERO_TIME*3)); /* 300msec*/
  2490. #endif
  2491. return 0;
  2492. }
  2493. EXPORT_SYMBOL(synaptics_rmi4_proximity_enables);
  2494. #endif
  2495. static int synaptics_rmi4_check_status(struct synaptics_rmi4_data *rmi4_data)
  2496. {
  2497. int retval;
  2498. int timeout = CHECK_STATUS_TIMEOUT_MS;
  2499. unsigned char data;
  2500. struct synaptics_rmi4_f01_device_status status;
  2501. retval = synaptics_rmi4_i2c_read(rmi4_data,
  2502. rmi4_data->f01_data_base_addr,
  2503. status.data,
  2504. sizeof(status.data));
  2505. if (retval < 0)
  2506. return retval;
  2507. dev_info(&rmi4_data->i2c_client->dev, "%s: Device status[0x%02x] status.code[%d]\n",
  2508. __func__, status.data[0], status.status_code);
  2509. while (status.status_code == STATUS_CRC_IN_PROGRESS) {
  2510. if (timeout > 0)
  2511. msleep(20);
  2512. else
  2513. return -1;
  2514. retval = synaptics_rmi4_i2c_read(rmi4_data,
  2515. rmi4_data->f01_data_base_addr,
  2516. status.data,
  2517. sizeof(status.data));
  2518. if (retval < 0)
  2519. return retval;
  2520. timeout -= 20;
  2521. }
  2522. if (status.flash_prog == 1) {
  2523. rmi4_data->flash_prog_mode = true;
  2524. dev_info(&rmi4_data->i2c_client->dev, "%s: In flash prog mode, status = 0x%02x\n",
  2525. __func__, status.status_code);
  2526. } else {
  2527. rmi4_data->flash_prog_mode = false;
  2528. }
  2529. retval = synaptics_rmi4_i2c_read(rmi4_data,
  2530. rmi4_data->f01_data_base_addr,
  2531. &data,
  2532. sizeof(data));
  2533. if (retval < 0) {
  2534. dev_err(&rmi4_data->i2c_client->dev,
  2535. "%s: Failed to read interrupt status\n",
  2536. __func__);
  2537. return retval;
  2538. }
  2539. return 0;
  2540. }
  2541. static void synaptics_rmi4_set_configured(struct synaptics_rmi4_data *rmi4_data)
  2542. {
  2543. int retval;
  2544. unsigned char device_ctrl;
  2545. retval = synaptics_rmi4_i2c_read(rmi4_data,
  2546. rmi4_data->f01_ctrl_base_addr,
  2547. &device_ctrl,
  2548. sizeof(device_ctrl));
  2549. if (retval < 0) {
  2550. dev_err(&(rmi4_data->i2c_client->dev),
  2551. "%s: Failed to set configured\n",
  2552. __func__);
  2553. return;
  2554. }
  2555. device_ctrl |= CONFIGURED;
  2556. retval = synaptics_rmi4_i2c_write(rmi4_data,
  2557. rmi4_data->f01_ctrl_base_addr,
  2558. &device_ctrl,
  2559. sizeof(device_ctrl));
  2560. if (retval < 0) {
  2561. dev_err(&(rmi4_data->i2c_client->dev),
  2562. "%s: Failed to set configured\n",
  2563. __func__);
  2564. }
  2565. return;
  2566. }
  2567. static int synaptics_rmi4_alloc_fh(struct synaptics_rmi4_fn **fhandler,
  2568. struct synaptics_rmi4_fn_desc *rmi_fd, int page_number)
  2569. {
  2570. *fhandler = kzalloc(sizeof(**fhandler), GFP_KERNEL);
  2571. if (!(*fhandler))
  2572. return -ENOMEM;
  2573. (*fhandler)->full_addr.data_base =
  2574. (rmi_fd->data_base_addr |
  2575. (page_number << 8));
  2576. (*fhandler)->full_addr.ctrl_base =
  2577. (rmi_fd->ctrl_base_addr |
  2578. (page_number << 8));
  2579. (*fhandler)->full_addr.cmd_base =
  2580. (rmi_fd->cmd_base_addr |
  2581. (page_number << 8));
  2582. (*fhandler)->full_addr.query_base =
  2583. (rmi_fd->query_base_addr |
  2584. (page_number << 8));
  2585. return 0;
  2586. }
  2587. /**
  2588. * synaptics_rmi4_query_device()
  2589. *
  2590. * Called by synaptics_rmi4_probe().
  2591. *
  2592. * This funtion scans the page description table, records the offsets
  2593. * to the register types of Function $01, sets up the function handlers
  2594. * for Function $11 and Function $12, determines the number of interrupt
  2595. * sources from the sensor, adds valid Functions with data inputs to the
  2596. * Function linked list, parses information from the query registers of
  2597. * Function $01, and enables the interrupt sources from the valid Functions
  2598. * with data inputs.
  2599. */
  2600. static int synaptics_rmi4_query_device(struct synaptics_rmi4_data *rmi4_data)
  2601. {
  2602. int retval;
  2603. unsigned char ii = 0;
  2604. unsigned char page_number;
  2605. unsigned char intr_count = 0;
  2606. unsigned char f01_query[F01_STD_QUERY_LEN];
  2607. unsigned short pdt_entry_addr;
  2608. unsigned short intr_addr;
  2609. struct synaptics_rmi4_fn_desc rmi_fd;
  2610. struct synaptics_rmi4_fn *fhandler;
  2611. struct synaptics_rmi4_device_info *rmi;
  2612. rmi = &(rmi4_data->rmi4_mod_info);
  2613. INIT_LIST_HEAD(&rmi->support_fn_list);
  2614. /* Scan the page description tables of the pages to service */
  2615. for (page_number = 0; page_number < PAGES_TO_SERVICE; page_number++) {
  2616. for (pdt_entry_addr = PDT_START; pdt_entry_addr > PDT_END;
  2617. pdt_entry_addr -= PDT_ENTRY_SIZE) {
  2618. pdt_entry_addr |= (page_number << 8);
  2619. retval = synaptics_rmi4_i2c_read(rmi4_data,
  2620. pdt_entry_addr,
  2621. (unsigned char *)&rmi_fd,
  2622. sizeof(rmi_fd));
  2623. if (retval < 0)
  2624. return retval;
  2625. fhandler = NULL;
  2626. if (rmi_fd.fn_number == 0) {
  2627. dev_dbg(&rmi4_data->i2c_client->dev,
  2628. "%s: Reached end of PDT\n",
  2629. __func__);
  2630. break;
  2631. }
  2632. /* Display function description infomation */
  2633. dev_dbg(&rmi4_data->i2c_client->dev, "%s: F%02x found (page %d): INT_SRC[%02X] BASE_ADDRS[%02X,%02X,%02X,%02x]\n",
  2634. __func__, rmi_fd.fn_number, page_number,
  2635. rmi_fd.intr_src_count, rmi_fd.data_base_addr,
  2636. rmi_fd.ctrl_base_addr, rmi_fd.cmd_base_addr,
  2637. rmi_fd.query_base_addr);
  2638. switch (rmi_fd.fn_number) {
  2639. case SYNAPTICS_RMI4_F01:
  2640. rmi4_data->f01_query_base_addr =
  2641. rmi_fd.query_base_addr;
  2642. rmi4_data->f01_ctrl_base_addr =
  2643. rmi_fd.ctrl_base_addr;
  2644. rmi4_data->f01_data_base_addr =
  2645. rmi_fd.data_base_addr;
  2646. rmi4_data->f01_cmd_base_addr =
  2647. rmi_fd.cmd_base_addr;
  2648. retval = synaptics_rmi4_check_status(rmi4_data);
  2649. if (retval < 0) {
  2650. dev_err(&rmi4_data->i2c_client->dev,
  2651. "%s: Failed to check status\n",
  2652. __func__);
  2653. return retval;
  2654. }
  2655. if (rmi4_data->flash_prog_mode)
  2656. goto flash_prog_mode;
  2657. break;
  2658. case SYNAPTICS_RMI4_F11:
  2659. if (rmi_fd.intr_src_count == 0)
  2660. break;
  2661. retval = synaptics_rmi4_alloc_fh(&fhandler,
  2662. &rmi_fd, page_number);
  2663. if (retval < 0) {
  2664. dev_err(&rmi4_data->i2c_client->dev,
  2665. "%s: Failed to alloc for F%d\n",
  2666. __func__,
  2667. rmi_fd.fn_number);
  2668. return retval;
  2669. }
  2670. retval = synaptics_rmi4_f11_init(rmi4_data,
  2671. fhandler, &rmi_fd, intr_count);
  2672. if (retval < 0)
  2673. return retval;
  2674. break;
  2675. case SYNAPTICS_RMI4_F12:
  2676. if (rmi_fd.intr_src_count == 0)
  2677. break;
  2678. retval = synaptics_rmi4_alloc_fh(&fhandler,
  2679. &rmi_fd, page_number);
  2680. if (retval < 0) {
  2681. dev_err(&rmi4_data->i2c_client->dev,
  2682. "%s: Failed to alloc for F%d\n",
  2683. __func__,
  2684. rmi_fd.fn_number);
  2685. return retval;
  2686. }
  2687. retval = synaptics_rmi4_f12_init(rmi4_data,
  2688. fhandler, &rmi_fd, intr_count);
  2689. if (retval < 0)
  2690. return retval;
  2691. break;
  2692. case SYNAPTICS_RMI4_F1A:
  2693. if (rmi_fd.intr_src_count == 0)
  2694. break;
  2695. retval = synaptics_rmi4_alloc_fh(&fhandler,
  2696. &rmi_fd, page_number);
  2697. if (retval < 0) {
  2698. dev_err(&rmi4_data->i2c_client->dev,
  2699. "%s: Failed to alloc for F%d\n",
  2700. __func__,
  2701. rmi_fd.fn_number);
  2702. return retval;
  2703. }
  2704. retval = synaptics_rmi4_f1a_init(rmi4_data,
  2705. fhandler, &rmi_fd, intr_count);
  2706. if (retval < 0)
  2707. return retval;
  2708. break;
  2709. case SYNAPTICS_RMI4_F34:
  2710. if (rmi_fd.intr_src_count == 0)
  2711. break;
  2712. retval = synaptics_rmi4_alloc_fh(&fhandler,
  2713. &rmi_fd, page_number);
  2714. if (retval < 0) {
  2715. dev_err(&rmi4_data->i2c_client->dev,
  2716. "%s: Failed to alloc for F%d\n",
  2717. __func__,
  2718. rmi_fd.fn_number);
  2719. return retval;
  2720. }
  2721. retval = synaptics_rmi4_f34_init(rmi4_data,
  2722. fhandler, &rmi_fd, intr_count);
  2723. if (retval < 0)
  2724. return retval;
  2725. break;
  2726. #ifdef PROXIMITY
  2727. case SYNAPTICS_RMI4_F51:
  2728. if (rmi_fd.intr_src_count == 0)
  2729. break;
  2730. retval = synaptics_rmi4_alloc_fh(&fhandler,
  2731. &rmi_fd, page_number);
  2732. if (retval < 0) {
  2733. dev_err(&rmi4_data->i2c_client->dev,
  2734. "%s: Failed to alloc for F%d\n",
  2735. __func__,
  2736. rmi_fd.fn_number);
  2737. return retval;
  2738. }
  2739. retval = synaptics_rmi4_f51_init(rmi4_data,
  2740. fhandler, &rmi_fd, intr_count);
  2741. if (retval < 0)
  2742. return retval;
  2743. break;
  2744. #endif
  2745. }
  2746. /* Accumulate the interrupt count */
  2747. intr_count += (rmi_fd.intr_src_count & MASK_3BIT);
  2748. if (fhandler && rmi_fd.intr_src_count) {
  2749. list_add_tail(&fhandler->link,
  2750. &rmi->support_fn_list);
  2751. }
  2752. }
  2753. }
  2754. flash_prog_mode:
  2755. rmi4_data->num_of_intr_regs = (intr_count + 7) / 8;
  2756. dev_info(&rmi4_data->i2c_client->dev,
  2757. "%s: Number of interrupt registers = %d sum of intr_count = %d\n",
  2758. __func__, rmi4_data->num_of_intr_regs, intr_count);
  2759. retval = synaptics_rmi4_i2c_read(rmi4_data,
  2760. rmi4_data->f01_query_base_addr,
  2761. f01_query,
  2762. sizeof(f01_query));
  2763. if (retval < 0)
  2764. return retval;
  2765. /* RMI Version 4.0 currently supported */
  2766. rmi->version_major = 4;
  2767. rmi->version_minor = 0;
  2768. rmi->manufacturer_id = f01_query[0];
  2769. rmi->product_props = f01_query[1];
  2770. rmi->product_info[0] = f01_query[2] & MASK_7BIT;
  2771. rmi->product_info[1] = f01_query[3] & MASK_7BIT;
  2772. rmi->date_code[0] = f01_query[4] & MASK_5BIT;
  2773. rmi->date_code[1] = f01_query[5] & MASK_4BIT;
  2774. rmi->date_code[2] = f01_query[6] & MASK_5BIT;
  2775. rmi->tester_id = ((f01_query[7] & MASK_7BIT) << 8) |
  2776. (f01_query[8] & MASK_7BIT);
  2777. rmi->serial_number = ((f01_query[9] & MASK_7BIT) << 8) |
  2778. (f01_query[10] & MASK_7BIT);
  2779. memcpy(rmi->product_id_string, &f01_query[11], 10);
  2780. if (rmi->manufacturer_id != 1) {
  2781. dev_err(&rmi4_data->i2c_client->dev,
  2782. "%s: Non-Synaptics device found, manufacturer ID = %d\n",
  2783. __func__, rmi->manufacturer_id);
  2784. }
  2785. retval = synaptics_rmi4_i2c_read(rmi4_data,
  2786. rmi4_data->f01_query_base_addr + F01_BUID_ID_OFFSET,
  2787. rmi->build_id,
  2788. sizeof(rmi->build_id));
  2789. if (retval < 0)
  2790. return retval;
  2791. memset(rmi4_data->intr_mask, 0x00, sizeof(rmi4_data->intr_mask));
  2792. /*
  2793. * Map out the interrupt bit masks for the interrupt sources
  2794. * from the registered function handlers.
  2795. */
  2796. if (!list_empty(&rmi->support_fn_list)) {
  2797. list_for_each_entry(fhandler, &rmi->support_fn_list, link) {
  2798. if (fhandler->num_of_data_sources) {
  2799. rmi4_data->intr_mask[fhandler->intr_reg_num] |=
  2800. fhandler->intr_mask;
  2801. }
  2802. /* To display each fhandler data */
  2803. dev_info(&rmi4_data->i2c_client->dev, "%s: F%02x : NUM_SOURCE[%02X] NUM_INT_REG[%02X] INT_MASK[%02X]\n",
  2804. __func__, fhandler->fn_number,
  2805. fhandler->num_of_data_sources, fhandler->intr_reg_num,
  2806. fhandler->intr_mask);
  2807. }
  2808. }
  2809. /* Enable the interrupt sources */
  2810. for (ii = 0; ii < rmi4_data->num_of_intr_regs; ii++) {
  2811. if (rmi4_data->intr_mask[ii] != 0x00) {
  2812. dev_info(&rmi4_data->i2c_client->dev,
  2813. "%s: Interrupt enable mask %d = 0x%02x\n",
  2814. __func__, ii, rmi4_data->intr_mask[ii]);
  2815. intr_addr = rmi4_data->f01_ctrl_base_addr + 1 + ii;
  2816. retval = synaptics_rmi4_i2c_write(rmi4_data,
  2817. intr_addr,
  2818. &(rmi4_data->intr_mask[ii]),
  2819. sizeof(rmi4_data->intr_mask[ii]));
  2820. if (retval < 0)
  2821. return retval;
  2822. }
  2823. }
  2824. synaptics_rmi4_set_configured(rmi4_data);
  2825. return 0;
  2826. }
  2827. static void synaptics_rmi4_release_support_fn(struct synaptics_rmi4_data *rmi4_data)
  2828. {
  2829. struct synaptics_rmi4_fn *fhandler, *n;
  2830. struct synaptics_rmi4_device_info *rmi;
  2831. rmi = &(rmi4_data->rmi4_mod_info);
  2832. if (list_empty(&rmi->support_fn_list)) {
  2833. dev_err(&rmi4_data->i2c_client->dev, "%s: support_fn_list is empty\n",
  2834. __func__);
  2835. goto out;
  2836. }
  2837. list_for_each_entry_safe(fhandler, n, &rmi->support_fn_list, link) {
  2838. dev_dbg(&rmi4_data->i2c_client->dev, "%s: fn_number = %x\n",
  2839. __func__, fhandler->fn_number);
  2840. if (fhandler->fn_number == SYNAPTICS_RMI4_F1A)
  2841. synaptics_rmi4_f1a_kfree(fhandler);
  2842. else
  2843. kfree(fhandler->data);
  2844. kfree(fhandler);
  2845. }
  2846. out:
  2847. #ifdef PROXIMITY
  2848. kfree(f51);
  2849. f51 = NULL;
  2850. #endif
  2851. }
  2852. static int synaptics_rmi4_set_input_device
  2853. (struct synaptics_rmi4_data *rmi4_data)
  2854. {
  2855. int retval;
  2856. unsigned char ii;
  2857. struct synaptics_rmi4_f1a_handle *f1a;
  2858. struct synaptics_rmi4_fn *fhandler;
  2859. struct synaptics_rmi4_device_info *rmi;
  2860. rmi = &(rmi4_data->rmi4_mod_info);
  2861. rmi4_data->input_dev = input_allocate_device();
  2862. if (rmi4_data->input_dev == NULL) {
  2863. dev_err(&rmi4_data->i2c_client->dev,
  2864. "%s: Failed to allocate input device\n",
  2865. __func__);
  2866. retval = -ENOMEM;
  2867. goto err_input_device;
  2868. }
  2869. retval = synaptics_rmi4_query_device(rmi4_data);
  2870. if (retval < 0) {
  2871. dev_err(&rmi4_data->i2c_client->dev,
  2872. "%s: Failed to query device\n",
  2873. __func__);
  2874. goto err_query_device;
  2875. }
  2876. rmi4_data->input_dev->name = "sec_touchscreen";
  2877. rmi4_data->input_dev->id.bustype = BUS_I2C;
  2878. rmi4_data->input_dev->dev.parent = &rmi4_data->i2c_client->dev;
  2879. #ifdef USE_OPEN_CLOSE
  2880. rmi4_data->input_dev->open = synaptics_rmi4_input_open;
  2881. rmi4_data->input_dev->close = synaptics_rmi4_input_close;
  2882. #endif
  2883. input_set_drvdata(rmi4_data->input_dev, rmi4_data);
  2884. #ifdef CONFIG_GLOVE_TOUCH
  2885. input_set_capability(rmi4_data->input_dev, EV_SW, SW_GLOVE);
  2886. #endif
  2887. set_bit(EV_SYN, rmi4_data->input_dev->evbit);
  2888. set_bit(EV_KEY, rmi4_data->input_dev->evbit);
  2889. set_bit(EV_ABS, rmi4_data->input_dev->evbit);
  2890. #if defined(CONFIG_SEC_MELIUSCA_PROJECT)
  2891. set_bit(EV_LED, rmi4_data->input_dev->evbit);
  2892. set_bit(LED_MISC, rmi4_data->input_dev->ledbit);
  2893. #endif
  2894. set_bit(BTN_TOUCH, rmi4_data->input_dev->keybit);
  2895. set_bit(BTN_TOOL_FINGER, rmi4_data->input_dev->keybit);
  2896. #ifdef INPUT_PROP_DIRECT
  2897. set_bit(INPUT_PROP_DIRECT, rmi4_data->input_dev->propbit);
  2898. #endif
  2899. input_set_abs_params(rmi4_data->input_dev,
  2900. ABS_MT_POSITION_X, 0,
  2901. rmi4_data->board->sensor_max_x, 0, 0);
  2902. input_set_abs_params(rmi4_data->input_dev,
  2903. ABS_MT_POSITION_Y, 0,
  2904. rmi4_data->board->sensor_max_y, 0, 0);
  2905. #ifdef REPORT_2D_W
  2906. #ifdef EDGE_SWIPE
  2907. input_set_abs_params(rmi4_data->input_dev,
  2908. ABS_MT_TOUCH_MAJOR, 0,
  2909. EDGE_SWIPE_WIDTH_MAX, 0, 0);
  2910. input_set_abs_params(rmi4_data->input_dev,
  2911. ABS_MT_TOUCH_MINOR, 0,
  2912. EDGE_SWIPE_WIDTH_MAX, 0, 0);
  2913. #else
  2914. input_set_abs_params(rmi4_data->input_dev,
  2915. ABS_MT_TOUCH_MAJOR, 0,
  2916. rmi4_data->board->max_touch_width, 0, 0);
  2917. input_set_abs_params(rmi4_data->input_dev,
  2918. ABS_MT_TOUCH_MINOR, 0,
  2919. rmi4_data->board->max_touch_width, 0, 0);
  2920. #endif
  2921. #endif
  2922. #ifdef PROXIMITY
  2923. input_set_abs_params(rmi4_data->input_dev,
  2924. ABS_MT_DISTANCE, 0,
  2925. HOVER_Z_MAX, 0, 0);
  2926. #ifdef EDGE_SWIPE
  2927. input_set_abs_params(rmi4_data->input_dev,
  2928. ABS_MT_WIDTH_MAJOR, 0,
  2929. EDGE_SWIPE_WIDTH_MAX, 0, 0);
  2930. input_set_abs_params(rmi4_data->input_dev,
  2931. ABS_MT_PALM, 0,
  2932. EDGE_SWIPE_PALM_MAX, 0, 0);
  2933. #endif
  2934. setup_timer(&rmi4_data->f51_finger_timer,
  2935. synaptics_rmi4_f51_finger_timer,
  2936. (unsigned long)rmi4_data);
  2937. #endif
  2938. #ifdef TYPE_B_PROTOCOL
  2939. input_mt_init_slots(rmi4_data->input_dev,
  2940. rmi4_data->num_of_fingers);
  2941. #endif
  2942. f1a = NULL;
  2943. if (!list_empty(&rmi->support_fn_list)) {
  2944. list_for_each_entry(fhandler, &rmi->support_fn_list, link) {
  2945. if (fhandler->fn_number == SYNAPTICS_RMI4_F1A)
  2946. f1a = fhandler->data;
  2947. }
  2948. }
  2949. if (f1a) {
  2950. for (ii = 0; ii < f1a->valid_button_count; ii++) {
  2951. set_bit(f1a->button_map[ii],
  2952. rmi4_data->input_dev->keybit);
  2953. input_set_capability(rmi4_data->input_dev,
  2954. EV_KEY, f1a->button_map[ii]);
  2955. }
  2956. }
  2957. retval = input_register_device(rmi4_data->input_dev);
  2958. if (retval) {
  2959. dev_err(&rmi4_data->i2c_client->dev,
  2960. "%s: Failed to register input device\n",
  2961. __func__);
  2962. goto err_register_input;
  2963. }
  2964. return 0;
  2965. err_register_input:
  2966. input_free_device(rmi4_data->input_dev);
  2967. err_query_device:
  2968. synaptics_rmi4_release_support_fn(rmi4_data);
  2969. err_input_device:
  2970. return retval;
  2971. }
  2972. #ifdef CONFIG_SEC_TSP_FACTORY
  2973. #include <asm/uaccess.h>
  2974. #define LCD_LDI_FILE_PATH "/sys/class/lcd/panel/window_type"
  2975. static int synaptics_rmi4_open_lcd_ldi(struct synaptics_rmi4_data *rmi4_data)
  2976. {
  2977. int iRet = 0;
  2978. mm_segment_t old_fs;
  2979. struct file *window_type;
  2980. unsigned char lcdtype[4] = {0,};
  2981. old_fs = get_fs();
  2982. set_fs(KERNEL_DS);
  2983. window_type = filp_open(LCD_LDI_FILE_PATH, O_RDONLY, 0666);
  2984. if (IS_ERR(window_type)) {
  2985. iRet = PTR_ERR(window_type);
  2986. if (iRet != -ENOENT)
  2987. dev_err(&rmi4_data->i2c_client->dev, "%s: window_type file open fail\n", __func__);
  2988. set_fs(old_fs);
  2989. goto exit;
  2990. }
  2991. iRet = window_type->f_op->read(window_type, (u8 *)lcdtype, sizeof(u8) * 4, &window_type->f_pos);
  2992. if (iRet != (sizeof(u8) * 4)) {
  2993. dev_err(&rmi4_data->i2c_client->dev, "%s: Can't read the lcd ldi data\n", __func__);
  2994. iRet = -EIO;
  2995. }
  2996. /* The variable of lcdtype has ASCII values(40 81 45) at 0x08 OCTA,
  2997. * so if someone need a TSP panel revision then to read third parameter.*/
  2998. rmi4_data->panel_revision = lcdtype[3] & 0x0F;
  2999. dev_info(&rmi4_data->i2c_client->dev,
  3000. "%s: update panel_revision 0x%02X\n", __func__, rmi4_data->panel_revision);
  3001. filp_close(window_type, current->files);
  3002. set_fs(old_fs);
  3003. exit:
  3004. return iRet;
  3005. }
  3006. #endif
  3007. static int synaptics_rmi4_reinit_device(struct synaptics_rmi4_data *rmi4_data)
  3008. {
  3009. int retval;
  3010. unsigned char ii = 0;
  3011. unsigned short intr_addr;
  3012. struct synaptics_rmi4_fn *fhandler;
  3013. struct synaptics_rmi4_device_info *rmi;
  3014. rmi = &(rmi4_data->rmi4_mod_info);
  3015. if (!list_empty(&rmi->support_fn_list)) {
  3016. list_for_each_entry(fhandler, &rmi->support_fn_list, link) {
  3017. if (fhandler->fn_number == SYNAPTICS_RMI4_F12) {
  3018. retval = synaptics_rmi4_f12_set_enables(rmi4_data, 0);
  3019. if (retval < 0)
  3020. return retval;
  3021. }
  3022. #ifdef CONFIG_SEC_TSP_FACTORY
  3023. /* Read firmware version from IC when every power up IC.
  3024. * During Factory process touch panel can be changed manually.
  3025. */
  3026. if (fhandler->fn_number == SYNAPTICS_RMI4_F34) {
  3027. synaptics_rmi4_open_lcd_ldi(rmi4_data);
  3028. retval = synaptics_rmi4_f34_read_version(rmi4_data, fhandler);
  3029. if (retval < 0)
  3030. return retval;
  3031. }
  3032. #endif
  3033. }
  3034. }
  3035. #ifdef CONFIG_GLOVE_TOUCH
  3036. synaptics_rmi4_glove_mode_enables(rmi4_data);
  3037. #endif
  3038. #ifdef PROXIMITY
  3039. if (!f51) {
  3040. dev_info(&rmi4_data->i2c_client->dev,
  3041. "%s: f51 is no available.\n", __func__);
  3042. } else {
  3043. retval = synaptics_rmi4_f51_set_init(rmi4_data);
  3044. if (retval < 0) {
  3045. dev_err(&rmi4_data->i2c_client->dev, "%s: fail proximity set init\n",
  3046. __func__);
  3047. return retval;
  3048. }
  3049. }
  3050. #endif
  3051. for (ii = 0; ii < rmi4_data->num_of_intr_regs; ii++) {
  3052. if (rmi4_data->intr_mask[ii] != 0x00) {
  3053. dev_info(&rmi4_data->i2c_client->dev,
  3054. "%s: Interrupt enable mask register[%d] = 0x%02x\n",
  3055. __func__, ii, rmi4_data->intr_mask[ii]);
  3056. intr_addr = rmi4_data->f01_ctrl_base_addr + 1 + ii;
  3057. retval = synaptics_rmi4_i2c_write(rmi4_data,
  3058. intr_addr,
  3059. &(rmi4_data->intr_mask[ii]),
  3060. sizeof(rmi4_data->intr_mask[ii]));
  3061. if (retval < 0)
  3062. return retval;
  3063. }
  3064. }
  3065. synaptics_rmi4_set_configured(rmi4_data);
  3066. return 0;
  3067. }
  3068. static void synaptics_rmi4_release_all_finger(
  3069. struct synaptics_rmi4_data *rmi4_data)
  3070. {
  3071. int ii;
  3072. #ifdef TYPE_B_PROTOCOL
  3073. for (ii = 0; ii < rmi4_data->num_of_fingers; ii++) {
  3074. input_mt_slot(rmi4_data->input_dev, ii);
  3075. input_mt_report_slot_state(rmi4_data->input_dev,
  3076. MT_TOOL_FINGER, 0);
  3077. }
  3078. #else
  3079. input_mt_sync(rmi4_data->input_dev);
  3080. #endif
  3081. input_report_key(rmi4_data->input_dev,
  3082. BTN_TOUCH, 0);
  3083. #ifdef CONFIG_GLOVE_TOUCH
  3084. input_report_switch(rmi4_data->input_dev,
  3085. SW_GLOVE, false);
  3086. rmi4_data->touchkey_glove_mode_status = false;
  3087. #endif
  3088. input_sync(rmi4_data->input_dev);
  3089. rmi4_data->fingers_on_2d = false;
  3090. #ifdef PROXIMITY
  3091. rmi4_data->f51_finger = false;
  3092. #endif
  3093. #ifdef TSP_BOOSTER
  3094. synaptics_set_dvfs_lock(rmi4_data, -1);
  3095. dev_info(&rmi4_data->i2c_client->dev,
  3096. "%s: dvfs_lock free.\n", __func__);
  3097. #endif
  3098. #ifdef USE_CUSTOM_REZERO
  3099. cancel_delayed_work(&rmi4_data->rezero_work);
  3100. #endif
  3101. }
  3102. static int synaptics_rmi4_reset_device(struct synaptics_rmi4_data *rmi4_data)
  3103. {
  3104. int retval;
  3105. unsigned char command = 0x01;
  3106. mutex_lock(&(rmi4_data->rmi4_reset_mutex));
  3107. disable_irq(rmi4_data->i2c_client->irq);
  3108. synaptics_rmi4_release_all_finger(rmi4_data);
  3109. if (!rmi4_data->stay_awake) {
  3110. retval = synaptics_rmi4_i2c_write(rmi4_data,
  3111. rmi4_data->f01_cmd_base_addr,
  3112. &command,
  3113. sizeof(command));
  3114. if (retval < 0) {
  3115. dev_err(&rmi4_data->i2c_client->dev,
  3116. "%s: Failed to issue reset command, error = %d\n",
  3117. __func__, retval);
  3118. goto out;
  3119. }
  3120. msleep(SYNAPTICS_HW_RESET_TIME);
  3121. } else {
  3122. #if defined(CONFIG_TOUCHSCREEN_SYNAPTICS_PREVENT_HSYNC_LEAKAGE)
  3123. rmi4_data->board->hsync_onoff(false);
  3124. #endif
  3125. synaptics_power_ctrl(rmi4_data,false);
  3126. msleep(30);
  3127. synaptics_power_ctrl(rmi4_data,true);
  3128. rmi4_data->current_page = MASK_8BIT; // added Page masking routine for ghost touch
  3129. msleep(SYNAPTICS_HW_RESET_TIME);
  3130. #if defined(CONFIG_TOUCHSCREEN_SYNAPTICS_PREVENT_HSYNC_LEAKAGE)
  3131. rmi4_data->board->hsync_onoff(true);
  3132. #endif
  3133. retval = synaptics_rmi4_f54_set_control(rmi4_data);
  3134. if (retval < 0)
  3135. dev_err(&rmi4_data->i2c_client->dev,
  3136. "%s: Failed to set f54 control\n",
  3137. __func__);
  3138. }
  3139. synaptics_rmi4_release_support_fn(rmi4_data);
  3140. retval = synaptics_rmi4_query_device(rmi4_data);
  3141. if (retval < 0) {
  3142. dev_err(&rmi4_data->i2c_client->dev,
  3143. "%s: Failed to query device\n",
  3144. __func__);
  3145. }
  3146. out:
  3147. enable_irq(rmi4_data->i2c_client->irq);
  3148. mutex_unlock(&(rmi4_data->rmi4_reset_mutex));
  3149. return 0;
  3150. }
  3151. #ifdef TSP_PATTERN_TRACKING_METHOD
  3152. static void synaptics_rmi4_reboot_work(struct work_struct *work)
  3153. {
  3154. int retval;
  3155. struct synaptics_rmi4_data *rmi4_data =
  3156. container_of(work, struct synaptics_rmi4_data,
  3157. reboot_work.work);
  3158. if(rmi4_data->ftouch_reboot == 1) return;
  3159. rmi4_data->ftouch_reboot = 1;
  3160. mutex_lock(&(rmi4_data->rmi4_reset_mutex));
  3161. disable_irq(rmi4_data->i2c_client->irq);
  3162. synaptics_rmi4_release_all_finger(rmi4_data);
  3163. ghosttouchcount++;
  3164. dev_err(&rmi4_data->i2c_client->dev,
  3165. ": Tsp Reboot(%d) by pattern tracking\n",ghosttouchcount);
  3166. #if defined(CONFIG_TOUCHSCREEN_SYNAPTICS_PREVENT_HSYNC_LEAKAGE)
  3167. rmi4_data->board->hsync_onoff(false);
  3168. #endif
  3169. synaptics_power_ctrl(rmi4_data,false);
  3170. msleep(50);
  3171. synaptics_power_ctrl(rmi4_data,true);
  3172. msleep(SYNAPTICS_HW_RESET_TIME);
  3173. #if defined(CONFIG_TOUCHSCREEN_SYNAPTICS_PREVENT_HSYNC_LEAKAGE)
  3174. rmi4_data->board->hsync_onoff(true);
  3175. #endif
  3176. retval = synaptics_rmi4_f54_set_control(rmi4_data);
  3177. if (retval < 0)
  3178. dev_err(&rmi4_data->i2c_client->dev,
  3179. "%s: Failed to set f54 control\n",
  3180. __func__);
  3181. synaptics_rmi4_release_support_fn(rmi4_data);
  3182. retval = synaptics_rmi4_query_device(rmi4_data);
  3183. if (retval < 0) {
  3184. dev_err(&rmi4_data->i2c_client->dev,
  3185. "%s: Failed to query device\n",
  3186. __func__);
  3187. }
  3188. enable_irq(rmi4_data->i2c_client->irq);
  3189. mutex_unlock(&(rmi4_data->rmi4_reset_mutex));
  3190. rmi4_data->ftouch_reboot = 0;
  3191. }
  3192. #endif
  3193. #ifdef SYNAPTICS_RMI_INFORM_CHARGER
  3194. extern void synaptics_tsp_register_callback(struct synaptics_rmi_callbacks *cb);
  3195. static void synaptics_charger_conn(struct synaptics_rmi4_data *rmi4_data,
  3196. int ta_status)
  3197. {
  3198. int retval;
  3199. unsigned char charger_connected;
  3200. retval = synaptics_rmi4_i2c_read(rmi4_data,
  3201. rmi4_data->f01_ctrl_base_addr,
  3202. &charger_connected,
  3203. sizeof(charger_connected));
  3204. if (retval < 0) {
  3205. dev_err(&(rmi4_data->input_dev->dev),
  3206. "%s: Failed to set configured\n",
  3207. __func__);
  3208. return;
  3209. }
  3210. if (ta_status == 0x01 || ta_status == 0x03)
  3211. charger_connected |= CHARGER_CONNECTED;
  3212. else
  3213. charger_connected &= CHARGER_DISCONNECTED;
  3214. retval = synaptics_rmi4_i2c_write(rmi4_data,
  3215. rmi4_data->f01_ctrl_base_addr,
  3216. &charger_connected,
  3217. sizeof(charger_connected));
  3218. if (retval < 0) {
  3219. dev_err(&(rmi4_data->input_dev->dev),
  3220. "%s: Failed to set configured\n",
  3221. __func__);
  3222. }
  3223. dev_info(&rmi4_data->i2c_client->dev,
  3224. "%s: device_control : %x, ta_status : %x\n",
  3225. __func__, charger_connected, ta_status);
  3226. }
  3227. static void synaptics_ta_cb(struct synaptics_rmi_callbacks *cb, int ta_status)
  3228. {
  3229. struct synaptics_rmi4_data *rmi4_data =
  3230. container_of(cb, struct synaptics_rmi4_data, callbacks);
  3231. dev_info(&rmi4_data->i2c_client->dev,
  3232. "%s: ta_status : %x\n", __func__, ta_status);
  3233. rmi4_data->ta_status = ta_status;
  3234. /* if do not completed driver loading, ta_cb will not run. */
  3235. #ifdef TSP_INIT_COMPLETE
  3236. if (!rmi4_data->init_done.done) {
  3237. dev_err(&rmi4_data->i2c_client->dev,
  3238. "%s: until driver loading done.\n",
  3239. __func__);
  3240. return;
  3241. }
  3242. #endif
  3243. if (rmi4_data->touch_stopped || rmi4_data->doing_reflash) {
  3244. dev_err(&rmi4_data->i2c_client->dev,
  3245. "%s: device is in suspend state or reflash.\n",
  3246. __func__);
  3247. return;
  3248. }
  3249. synaptics_charger_conn(rmi4_data, ta_status);
  3250. }
  3251. #endif
  3252. #ifdef PROXIMITY
  3253. static void synaptics_rmi4_f51_finger_timer(unsigned long data)
  3254. {
  3255. struct synaptics_rmi4_data *rmi4_data =
  3256. (struct synaptics_rmi4_data *)data;
  3257. if (rmi4_data->f51_finger) {
  3258. rmi4_data->f51_finger = false;
  3259. mod_timer(&rmi4_data->f51_finger_timer,
  3260. jiffies + msecs_to_jiffies(F51_FINGER_TIMEOUT));
  3261. return;
  3262. }
  3263. if (!rmi4_data->fingers_on_2d) {
  3264. #ifdef TYPE_B_PROTOCOL
  3265. input_mt_slot(rmi4_data->input_dev, 0);
  3266. input_mt_report_slot_state(rmi4_data->input_dev,
  3267. MT_TOOL_FINGER, 0);
  3268. #else
  3269. input_mt_sync(rmi4_data->input_dev);
  3270. #endif
  3271. input_sync(rmi4_data->input_dev);
  3272. }
  3273. return;
  3274. }
  3275. #endif
  3276. static void synaptics_rmi4_remove_exp_fn(struct synaptics_rmi4_data *rmi4_data)
  3277. {
  3278. struct synaptics_rmi4_exp_fn *exp_fhandler, *n;
  3279. if (list_empty(&exp_fn_list)) {
  3280. dev_err(&rmi4_data->i2c_client->dev, "%s: exp_fn_list empty\n",
  3281. __func__);
  3282. return;
  3283. }
  3284. list_for_each_entry_safe(exp_fhandler, n, &exp_fn_list, link) {
  3285. if (exp_fhandler->initialized &&
  3286. (exp_fhandler->func_remove != NULL)) {
  3287. dev_dbg(&rmi4_data->i2c_client->dev, "%s: [%d]\n",
  3288. __func__, exp_fhandler->fn_type);
  3289. exp_fhandler->func_remove(rmi4_data);
  3290. }
  3291. list_del(&exp_fhandler->link);
  3292. kfree(exp_fhandler);
  3293. }
  3294. }
  3295. static int synaptics_rmi4_init_exp_fn(struct synaptics_rmi4_data *rmi4_data)
  3296. {
  3297. int retval;
  3298. struct synaptics_rmi4_exp_fn *exp_fhandler;
  3299. INIT_LIST_HEAD(&exp_fn_list);
  3300. retval = rmidev_module_register();
  3301. if (retval < 0) {
  3302. dev_err(&rmi4_data->i2c_client->dev,
  3303. "%s: Failed to register rmidev module\n",
  3304. __func__);
  3305. goto error_exit;
  3306. }
  3307. retval = rmi4_f54_module_register();
  3308. if (retval < 0) {
  3309. dev_err(&rmi4_data->i2c_client->dev,
  3310. "%s: Failed to register f54 module\n",
  3311. __func__);
  3312. goto error_exit;
  3313. }
  3314. retval = rmi4_fw_update_module_register();
  3315. if (retval < 0) {
  3316. dev_err(&rmi4_data->i2c_client->dev,
  3317. "%s: Failed to register fw update module\n",
  3318. __func__);
  3319. goto error_exit;
  3320. }
  3321. if (list_empty(&exp_fn_list))
  3322. return -ENODEV;
  3323. list_for_each_entry(exp_fhandler, &exp_fn_list, link) {
  3324. if (exp_fhandler->func_init != NULL) {
  3325. dev_dbg(&rmi4_data->i2c_client->dev, "%s: run [%d]'s init function\n",
  3326. __func__, exp_fhandler->fn_type);
  3327. retval = exp_fhandler->func_init(rmi4_data);
  3328. if (retval < 0) {
  3329. dev_err(&rmi4_data->i2c_client->dev,
  3330. "%s: Failed to init exp fn\n",
  3331. __func__);
  3332. goto error_exit;
  3333. } else {
  3334. exp_fhandler->initialized = true;
  3335. }
  3336. }
  3337. }
  3338. return 0;
  3339. error_exit:
  3340. synaptics_rmi4_remove_exp_fn(rmi4_data);
  3341. return retval;
  3342. }
  3343. /**
  3344. * synaptics_rmi4_new_function()
  3345. *
  3346. * Called by other expansion Function modules in their module init and
  3347. * module exit functions.
  3348. *
  3349. * This function is used by other expansion Function modules such as
  3350. * rmi_dev to register themselves with the driver by providing their
  3351. * initialization and removal callback function pointers so that they
  3352. * can be inserted or removed dynamically at module init and exit times,
  3353. * respectively.
  3354. */
  3355. int synaptics_rmi4_new_function(enum exp_fn fn_type,
  3356. int (*func_init)(struct synaptics_rmi4_data *rmi4_data),
  3357. void (*func_remove)(struct synaptics_rmi4_data *rmi4_data),
  3358. void (*func_attn)(struct synaptics_rmi4_data *rmi4_data,
  3359. unsigned char intr_mask))
  3360. {
  3361. struct synaptics_rmi4_exp_fn *exp_fhandler;
  3362. exp_fhandler = kzalloc(sizeof(*exp_fhandler), GFP_KERNEL);
  3363. if (!exp_fhandler) {
  3364. pr_err("%s: Failed to alloc mem for expansion function\n",
  3365. __func__);
  3366. return -ENOMEM;
  3367. }
  3368. exp_fhandler->fn_type = fn_type;
  3369. exp_fhandler->func_init = func_init;
  3370. exp_fhandler->func_attn = func_attn;
  3371. exp_fhandler->func_remove = func_remove;
  3372. list_add_tail(&exp_fhandler->link, &exp_fn_list);
  3373. return 0;
  3374. }
  3375. void synaptics_power_ctrl(struct synaptics_rmi4_data *rmi4_data, bool enable)
  3376. {
  3377. int ret = 0;
  3378. #if defined(CONFIG_SEC_H_PROJECT) || defined(CONFIG_SEC_JS_PROJECT) || defined(CONFIG_MACH_JSGLTE_CHN_CMCC)
  3379. static struct regulator *reg_l10;
  3380. #endif
  3381. pr_err("[synaptics] %s enable(%d)\n", __func__,enable);
  3382. ret = gpio_direction_output(rmi4_data->pwrdata->vdd_io_1p8, enable);
  3383. if (ret) {
  3384. pr_err("[TKEY]%s: unable to set_direction for vdd_led [%d]\n",
  3385. __func__, rmi4_data->pwrdata->vdd_io_1p8);
  3386. }
  3387. #if defined(CONFIG_SEC_H_PROJECT) || defined(CONFIG_SEC_JS_PROJECT) || defined(CONFIG_MACH_JSGLTE_CHN_CMCC)
  3388. if (!reg_l10) {
  3389. reg_l10 = regulator_get(NULL, "8941_l10");
  3390. if (IS_ERR(reg_l10)) {
  3391. pr_err("%s: could not get 8917_l10, rc = %ld\n",
  3392. __func__, PTR_ERR(reg_l10));
  3393. return;
  3394. }
  3395. ret = regulator_set_voltage(reg_l10, 1800000, 1800000);
  3396. if (ret) {
  3397. pr_err("%s: unable to set l10 voltage to 1.8V\n",
  3398. __func__);
  3399. return;
  3400. }
  3401. }
  3402. if (enable) {
  3403. if (regulator_is_enabled(reg_l10))
  3404. pr_err( "%s: L10(1.8V) is enabled\n", __func__);
  3405. else
  3406. ret = regulator_enable(reg_l10);
  3407. if (ret) {
  3408. pr_err("%s: enable l10 failed, rc=%d\n",
  3409. __func__, ret);
  3410. return;
  3411. }
  3412. pr_info("%s: tsp 1.8V on is finished.\n", __func__);
  3413. } else {
  3414. if (regulator_is_enabled(reg_l10))
  3415. ret = regulator_disable(reg_l10);
  3416. else
  3417. pr_err("%s: L10(1.8V) is disabled\n", __func__);
  3418. if (ret) {
  3419. pr_err("%s: disable l10 failed, rc=%d\n",
  3420. __func__, ret);
  3421. return;
  3422. }
  3423. pr_info("%s: tsp 1.8V off is finished.\n", __func__);
  3424. }
  3425. #endif
  3426. #if !defined(CONFIG_SEC_H_PROJECT) && !defined(CONFIG_SEC_JS_PROJECT) && !defined(CONFIG_MACH_JSGLTE_CHN_CMCC)
  3427. msleep(30);
  3428. #endif
  3429. return;
  3430. }
  3431. static int lcd_tsp_panel_version;
  3432. static int atoi(char *str)
  3433. {
  3434. int ret = 0;
  3435. int count = 0;
  3436. if (str == NULL)
  3437. return -EINVAL;
  3438. while (str[count] != (int)NULL && str[count] >= '0'
  3439. && str[count] <= 'z') {
  3440. ret = ret * 0x10 + str[count] - '0';
  3441. ++count;
  3442. }
  3443. return ret;
  3444. }
  3445. static int __init sec_tsp_mode(char *mode)
  3446. {
  3447. int ret, ret1;
  3448. ret = atoi(mode);
  3449. ret1 = ((ret >> 12) & 0X07);
  3450. lcd_tsp_panel_version = ret;
  3451. printk(KERN_ERR "%s: LCD_ID = 0x%s, val: 0X%x, ret1: 0x%x",
  3452. __func__, mode, ret, ret1);
  3453. // if (ret1 == 0x01 || ret1 == 0x04 || ret1 == 0x05 || ret == 0x0)
  3454. // sec_tsp_synaptics_mode = 1;
  3455. // else
  3456. // sec_tsp_synaptics_mode = 0;
  3457. return 1;
  3458. }
  3459. __setup("lcd_id=0x", sec_tsp_mode);
  3460. #ifdef CONFIG_SEC_TSP_FACTORY
  3461. unsigned int bootmode;
  3462. static int __init sec_tsp_reboot_mode(char *mode)
  3463. {
  3464. int ret;
  3465. ret = strncmp(mode, "1", 1);
  3466. if (ret == 0)
  3467. bootmode = 1;
  3468. else
  3469. bootmode = 0;
  3470. printk(KERN_ERR "%s: %d, %s\n", __func__, ret, mode);
  3471. return 1;
  3472. }
  3473. __setup("androidboot.check_recovery_condition=0x", sec_tsp_reboot_mode);
  3474. #endif
  3475. /**
  3476. * synaptics_rmi4_probe()
  3477. *
  3478. * Called by the kernel when an association with an I2C device of the
  3479. * same name is made (after doing i2c_add_driver).
  3480. *
  3481. * This funtion allocates and initializes the resources for the driver
  3482. * as an input driver, turns on the power to the sensor, queries the
  3483. * sensor for its supported Functions and characteristics, registers
  3484. * the driver to the input subsystem, sets up the interrupt, handles
  3485. * the registration of the early_suspend and late_resume functions,
  3486. * and creates a work queue for detection of other expansion Function
  3487. * modules.
  3488. */
  3489. static int __devinit synaptics_rmi4_probe(struct i2c_client *client,
  3490. const struct i2c_device_id *dev_id)
  3491. {
  3492. int retval;
  3493. unsigned char attr_count;
  3494. int attr_count_num;
  3495. struct synaptics_rmi4_data *rmi4_data;
  3496. struct synaptics_rmi4_device_info *rmi;
  3497. struct synaptics_rmi4_power_data *pdata;
  3498. int error;
  3499. #if !defined(CONFIG_SEC_MELIUSCA_PROJECT)
  3500. int touch_fpcb_version;
  3501. #endif
  3502. struct synaptics_rmi4_platform_data *platform_data;
  3503. platform_data = &rmi4_platformdata;
  3504. printk(KERN_ERR "TSP %s",__func__);
  3505. if (!i2c_check_functionality(client->adapter,
  3506. I2C_FUNC_SMBUS_BYTE_DATA)) {
  3507. dev_err(&client->dev,
  3508. "%s: SMBus byte data not supported\n",
  3509. __func__);
  3510. return -EIO;
  3511. }
  3512. if (client->dev.of_node) {
  3513. pdata = devm_kzalloc(&client->dev,
  3514. sizeof(struct synaptics_rmi4_power_data),
  3515. GFP_KERNEL);
  3516. if (!pdata) {
  3517. dev_err(&client->dev, "Failed to allocate memory\n");
  3518. return -ENOMEM;
  3519. }
  3520. error = synaptics_parse_dt(&client->dev, pdata);
  3521. if (error)
  3522. return error;
  3523. } else {
  3524. pdata = client->dev.platform_data;
  3525. printk(KERN_ERR "TSP failed to align dtsi %s",__func__);
  3526. }
  3527. synaptics_request_gpio(pdata);
  3528. if (!platform_data) {
  3529. dev_err(&client->dev,
  3530. "%s: No platform data found\n",
  3531. __func__);
  3532. return -EINVAL;
  3533. }
  3534. rmi4_data = kzalloc(sizeof(*rmi4_data), GFP_KERNEL);
  3535. if (!rmi4_data) {
  3536. dev_err(&client->dev,
  3537. "%s: Failed to alloc mem for rmi4_data\n",
  3538. __func__);
  3539. return -ENOMEM;
  3540. }
  3541. rmi = &(rmi4_data->rmi4_mod_info);
  3542. rmi4_data->i2c_client = client;
  3543. rmi4_data->current_page = MASK_8BIT;
  3544. rmi4_data->board = platform_data; // Take care
  3545. rmi4_data->pwrdata = pdata;
  3546. rmi4_data->touch_stopped = false;
  3547. rmi4_data->sensor_sleep = false;
  3548. rmi4_data->irq_enabled = false;
  3549. rmi4_data->tsp_probe = false;
  3550. rmi4_data->rebootcount = 0;
  3551. rmi4_data->panel_revision = rmi4_data->board->panel_revision;
  3552. rmi4_data->i2c_read = synaptics_rmi4_i2c_read;
  3553. rmi4_data->i2c_write = synaptics_rmi4_i2c_write;
  3554. rmi4_data->irq_enable = synaptics_rmi4_irq_enable;
  3555. rmi4_data->reset_device = synaptics_rmi4_reset_device;
  3556. rmi4_data->stop_device = synaptics_rmi4_stop_device;
  3557. rmi4_data->start_device = synaptics_rmi4_start_device;
  3558. #ifdef CONFIG_SEC_TSP_FACTORY
  3559. rmi4_data->bootmode = bootmode;
  3560. dev_info(&client->dev,
  3561. "%s: bootmode =%d\n",
  3562. __func__,bootmode);
  3563. #endif
  3564. #if !defined(CONFIG_SEC_MELIUSCA_PROJECT)
  3565. /* define panel version : M4 / M4+ */
  3566. printk(KERN_ERR "%s system_rev = %d, octa version =0x%x",__func__,system_rev,lcd_tsp_panel_version);
  3567. touch_fpcb_version = (lcd_tsp_panel_version & 0xF000) >> 12;
  3568. printk(KERN_ERR "%s touch_fpcb_version =0x%x",__func__,touch_fpcb_version);
  3569. /* Definition for firmware name according to panel ID
  3570. *
  3571. * ID, FPCB Name, User firmware, Factory firmware
  3572. * ~ 4, FPCB 3.4, FW_IMAGE_NAME_B0_3_4, FAC_FWIMAGE_NAME_B0
  3573. * ~ 4, FPCB 4.0, FW_IMAGE_NAME_B0_4_0, FAC_FWIMAGE_NAME_B0
  3574. * 5, FPCB 4.3, FW_IMAGE_NAME_B0_4_3, FAC_FWIMAGE_NAME_B0
  3575. * 6, FPCB 6.0, FW_IMAGE_NAME_B0_4_3, FAC_FWIMAGE_NAME_B0
  3576. * 7, FPCB 7.x, FW_IMAGE_NAME_B0_4_3, FAC_FWIMAGE_NAME_B0
  3577. * 8, FPCB 5.x, FW_IMAGE_NAME_B0_5_1, FAC_FWIMAGE_NAME_B0_5_1
  3578. */
  3579. #if defined(CONFIG_MACH_JACTIVESKT)
  3580. rmi4_data->panel_revision = OCTA_PANEL_REVISION_40;
  3581. rmi4_data->board->firmware_name = FW_IMAGE_NAME_B0_HSYNC04;
  3582. rmi4_data->board->fac_firmware_name = FW_IMAGE_NAME_B0_HSYNC04_FAC;
  3583. #else
  3584. if(touch_fpcb_version == OCTA_PANEL_REVISION_51){
  3585. rmi4_data->panel_revision = OCTA_PANEL_REVISION_51;
  3586. rmi4_data->board->firmware_name = FW_IMAGE_NAME_B0_5_1;
  3587. rmi4_data->board->fac_firmware_name = FAC_FWIMAGE_NAME_B0_5_1;
  3588. }
  3589. else{
  3590. rmi4_data->panel_revision = OCTA_PANEL_REVISION_43;
  3591. rmi4_data->board->firmware_name = FW_IMAGE_NAME_B0_4_3;
  3592. rmi4_data->board->fac_firmware_name = FAC_FWIMAGE_NAME_B0;
  3593. }
  3594. #endif
  3595. #else
  3596. rmi4_data->panel_revision = 0x00;
  3597. rmi4_data->board->firmware_name = FW_IMAGE_NAME_B0_NEP_14;
  3598. rmi4_data->board->fac_firmware_name = FW_IMAGE_NAME_B0_NEP_1F;
  3599. #endif
  3600. #if defined(CONFIG_TOUCHSCREEN_SYNAPTICS_PREVENT_HSYNC_LEAKAGE)
  3601. rmi4_data->board->hsync_onoff(false);
  3602. #endif
  3603. touch_sleep_time = SYNAPTICS_HW_RESET_TIME;
  3604. synaptics_power_ctrl(rmi4_data,true);
  3605. msleep(touch_sleep_time);
  3606. #if defined(CONFIG_TOUCHSCREEN_SYNAPTICS_PREVENT_HSYNC_LEAKAGE)
  3607. rmi4_data->board->hsync_onoff(true);
  3608. #endif
  3609. mutex_init(&(rmi4_data->rmi4_io_ctrl_mutex));
  3610. mutex_init(&(rmi4_data->rmi4_reset_mutex));
  3611. mutex_init(&(rmi4_data->rmi4_reflash_mutex));
  3612. mutex_init(&(rmi4_data->rmi4_device_mutex));
  3613. #ifdef TSP_INIT_COMPLETE
  3614. init_completion(&rmi4_data->init_done);
  3615. #endif
  3616. #ifdef USE_OPEN_DWORK
  3617. INIT_DELAYED_WORK(&rmi4_data->open_work, synaptics_rmi4_open_work);
  3618. #endif
  3619. #ifdef USE_CUSTOM_REZERO
  3620. INIT_DELAYED_WORK(&rmi4_data->rezero_work, synaptics_rmi4_rezero_work);
  3621. #endif
  3622. #ifdef TSP_PATTERN_TRACKING_METHOD
  3623. INIT_DELAYED_WORK(&rmi4_data->reboot_work, synaptics_rmi4_reboot_work);
  3624. #endif
  3625. i2c_set_clientdata(client, rmi4_data);
  3626. err_tsp_reboot:
  3627. #if defined(CONFIG_TOUCHSCREEN_SYNAPTICS_PREVENT_HSYNC_LEAKAGE)
  3628. rmi4_data->board->hsync_onoff(false);
  3629. #endif
  3630. synaptics_power_ctrl(rmi4_data,true);
  3631. msleep(SYNAPTICS_POWER_MARGIN_TIME);
  3632. #if defined(CONFIG_TOUCHSCREEN_SYNAPTICS_PREVENT_HSYNC_LEAKAGE)
  3633. rmi4_data->board->hsync_onoff(true);
  3634. #endif
  3635. #ifdef TSP_BOOSTER
  3636. synaptics_init_dvfs(rmi4_data);
  3637. #endif
  3638. retval = synaptics_rmi4_set_input_device(rmi4_data);
  3639. if (retval < 0) {
  3640. dev_err(&client->dev,
  3641. "%s: Failed to set up input device\n",
  3642. __func__);
  3643. if((retval == TSP_NEEDTO_REBOOT)&&(rmi4_data->rebootcount< MAX_TSP_REBOOT)){
  3644. synaptics_power_ctrl(rmi4_data,false);
  3645. msleep(SYNAPTICS_POWER_MARGIN_TIME);
  3646. msleep(SYNAPTICS_POWER_MARGIN_TIME);
  3647. rmi4_data->rebootcount++;
  3648. dev_err(&client->dev,
  3649. "%s: reboot sequence by i2c fail\n",
  3650. __func__);
  3651. goto err_tsp_reboot;
  3652. }
  3653. else goto err_set_input_device;
  3654. }
  3655. retval = synaptics_rmi4_init_exp_fn(rmi4_data);
  3656. if (retval < 0) {
  3657. dev_err(&client->dev,
  3658. "%s: Failed to register rmidev module\n",
  3659. __func__);
  3660. goto err_init_exp_fn;
  3661. }
  3662. /*
  3663. if (platform_data->gpio_config) {
  3664. retval = platform_data->gpio_config(platform_data->gpio, true);
  3665. if (retval < 0) {
  3666. dev_err(&client->dev,
  3667. "%s: Failed to configure GPIO\n",
  3668. __func__);
  3669. goto err_gpio;
  3670. }
  3671. }
  3672. */
  3673. client->irq = gpio_to_irq(pdata->tsp_int);
  3674. printk(KERN_ERR "%s: tsp : gpio_to_irq : %d\n", __func__, client->irq);
  3675. rmi4_data->irq = client->irq;
  3676. printk(KERN_ERR "%s: ln:%d\n", __func__, __LINE__);
  3677. retval = synaptics_rmi4_irq_enable(rmi4_data, true);
  3678. if (retval < 0) {
  3679. dev_err(&client->dev,
  3680. "%s: Failed to enable attention interrupt\n",
  3681. __func__);
  3682. goto err_enable_irq;
  3683. }
  3684. for (attr_count = 0; attr_count < ARRAY_SIZE(attrs); attr_count++) {
  3685. retval = sysfs_create_file(&rmi4_data->input_dev->dev.kobj,
  3686. &attrs[attr_count].attr);
  3687. if (retval < 0) {
  3688. dev_err(&client->dev,
  3689. "%s: Failed to create sysfs attributes\n",
  3690. __func__);
  3691. goto err_sysfs;
  3692. }
  3693. }
  3694. retval = synaptics_rmi4_fw_update_on_probe(rmi4_data);
  3695. if (retval < 0) {
  3696. dev_err(&client->dev, "%s: Failed to firmware update\n",
  3697. __func__);
  3698. }
  3699. #ifdef CONFIG_HAS_EARLYSUSPEND
  3700. rmi4_data->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN -2;
  3701. rmi4_data->early_suspend.suspend = synaptics_rmi4_early_suspend;
  3702. rmi4_data->early_suspend.resume = synaptics_rmi4_late_resume;
  3703. register_early_suspend(&rmi4_data->early_suspend);
  3704. #endif
  3705. #ifdef SYNAPTICS_RMI_INFORM_CHARGER
  3706. rmi4_data->register_cb = synaptics_tsp_register_callback;
  3707. rmi4_data->callbacks.inform_charger = synaptics_ta_cb;
  3708. if (rmi4_data->register_cb){
  3709. dev_err(&client->dev, "[TSP] Register TA Callback\n");
  3710. rmi4_data->register_cb(&rmi4_data->callbacks);
  3711. }
  3712. #endif
  3713. /* for blocking to be excuted open function until probing */
  3714. rmi4_data->tsp_probe = true;
  3715. #ifdef TSP_INIT_COMPLETE
  3716. complete_all(&rmi4_data->init_done);
  3717. #endif
  3718. #if !defined(CONFIG_SEC_MELIUSCA_PROJECT)
  3719. #ifdef TSP_TURNOFF_AFTER_PROBE
  3720. synaptics_rmi4_stop_device(rmi4_data);
  3721. #endif
  3722. #endif
  3723. return retval;
  3724. err_sysfs:
  3725. attr_count_num = (int)attr_count;
  3726. for (attr_count_num--; attr_count_num >= 0; attr_count_num--) {
  3727. sysfs_remove_file(&rmi4_data->input_dev->dev.kobj,
  3728. &attrs[attr_count].attr);
  3729. }
  3730. synaptics_rmi4_irq_enable(rmi4_data, false);
  3731. err_enable_irq:
  3732. synaptics_rmi4_remove_exp_fn(rmi4_data);
  3733. err_init_exp_fn:
  3734. synaptics_rmi4_release_support_fn(rmi4_data);
  3735. input_unregister_device(rmi4_data->input_dev);
  3736. rmi4_data->input_dev = NULL;
  3737. err_set_input_device:
  3738. synaptics_power_ctrl(rmi4_data,false);
  3739. #ifdef TSP_INIT_COMPLETE
  3740. complete_all(&rmi4_data->init_done);
  3741. #endif
  3742. kfree(rmi4_data);
  3743. return retval;
  3744. }
  3745. /**
  3746. * synaptics_rmi4_remove()
  3747. *
  3748. * Called by the kernel when the association with an I2C device of the
  3749. * same name is broken (when the driver is unloaded).
  3750. *
  3751. * This funtion terminates the work queue, stops sensor data acquisition,
  3752. * frees the interrupt, unregisters the driver from the input subsystem,
  3753. * turns off the power to the sensor, and frees other allocated resources.
  3754. */
  3755. static int __devexit synaptics_rmi4_remove(struct i2c_client *client)
  3756. {
  3757. unsigned char attr_count;
  3758. struct synaptics_rmi4_data *rmi4_data = i2c_get_clientdata(client);
  3759. struct synaptics_rmi4_device_info *rmi;
  3760. rmi = &(rmi4_data->rmi4_mod_info);
  3761. #ifdef CONFIG_HAS_EARLYSUSPEND
  3762. unregister_early_suspend(&rmi4_data->early_suspend);
  3763. #endif
  3764. synaptics_rmi4_irq_enable(rmi4_data, false);
  3765. for (attr_count = 0; attr_count < ARRAY_SIZE(attrs); attr_count++) {
  3766. sysfs_remove_file(&rmi4_data->input_dev->dev.kobj,
  3767. &attrs[attr_count].attr);
  3768. }
  3769. input_unregister_device(rmi4_data->input_dev);
  3770. synaptics_rmi4_remove_exp_fn(rmi4_data);
  3771. synaptics_power_ctrl(rmi4_data,false);
  3772. rmi4_data->touch_stopped = true;
  3773. synaptics_rmi4_release_support_fn(rmi4_data);
  3774. input_free_device(rmi4_data->input_dev);
  3775. kfree(rmi4_data);
  3776. return 0;
  3777. }
  3778. #ifdef USE_SENSOR_SLEEP
  3779. /**
  3780. * synaptics_rmi4_sensor_sleep()
  3781. *
  3782. * Called by synaptics_rmi4_early_suspend() and synaptics_rmi4_suspend().
  3783. *
  3784. * This function stops finger data acquisition and puts the sensor to sleep.
  3785. */
  3786. static void synaptics_rmi4_sensor_sleep(struct synaptics_rmi4_data *rmi4_data)
  3787. {
  3788. int retval;
  3789. unsigned char device_ctrl;
  3790. dev_info(&rmi4_data->i2c_client->dev, "%s\n", __func__);
  3791. retval = synaptics_rmi4_i2c_read(rmi4_data,
  3792. rmi4_data->f01_ctrl_base_addr,
  3793. &device_ctrl,
  3794. sizeof(device_ctrl));
  3795. if (retval < 0) {
  3796. dev_err(&(rmi4_data->i2c_client->dev),
  3797. "%s: Failed to enter sleep mode\n",
  3798. __func__);
  3799. rmi4_data->sensor_sleep = false;
  3800. return;
  3801. }
  3802. device_ctrl = (device_ctrl & ~MASK_3BIT);
  3803. device_ctrl = (device_ctrl | NO_SLEEP_OFF | SENSOR_SLEEP);
  3804. retval = synaptics_rmi4_i2c_write(rmi4_data,
  3805. rmi4_data->f01_ctrl_base_addr,
  3806. &device_ctrl,
  3807. sizeof(device_ctrl));
  3808. if (retval < 0) {
  3809. dev_err(&(rmi4_data->i2c_client->dev),
  3810. "%s: Failed to enter sleep mode\n",
  3811. __func__);
  3812. rmi4_data->sensor_sleep = false;
  3813. return;
  3814. } else {
  3815. rmi4_data->sensor_sleep = true;
  3816. }
  3817. return;
  3818. }
  3819. /**
  3820. * synaptics_rmi4_sensor_wake()
  3821. *
  3822. * Called by synaptics_rmi4_resume() and synaptics_rmi4_late_resume().
  3823. *
  3824. * This function wakes the sensor from sleep.
  3825. */
  3826. static void synaptics_rmi4_sensor_wake(struct synaptics_rmi4_data *rmi4_data)
  3827. {
  3828. int retval;
  3829. unsigned char device_ctrl;
  3830. dev_info(&rmi4_data->i2c_client->dev, "%s\n", __func__);
  3831. retval = synaptics_rmi4_i2c_read(rmi4_data,
  3832. rmi4_data->f01_ctrl_base_addr,
  3833. &device_ctrl,
  3834. sizeof(device_ctrl));
  3835. if (retval < 0) {
  3836. dev_err(&(rmi4_data->i2c_client->dev),
  3837. "%s: Failed to wake from sleep mode\n",
  3838. __func__);
  3839. rmi4_data->sensor_sleep = true;
  3840. return;
  3841. }
  3842. device_ctrl = (device_ctrl & ~MASK_3BIT);
  3843. device_ctrl = (device_ctrl | NO_SLEEP_OFF | NORMAL_OPERATION);
  3844. retval = synaptics_rmi4_i2c_write(rmi4_data,
  3845. rmi4_data->f01_ctrl_base_addr,
  3846. &device_ctrl,
  3847. sizeof(device_ctrl));
  3848. if (retval < 0) {
  3849. dev_err(&(rmi4_data->i2c_client->dev),
  3850. "%s: Failed to wake from sleep mode\n",
  3851. __func__);
  3852. rmi4_data->sensor_sleep = true;
  3853. return;
  3854. } else {
  3855. rmi4_data->sensor_sleep = false;
  3856. }
  3857. return;
  3858. }
  3859. #endif
  3860. static int synaptics_rmi4_stop_device(struct synaptics_rmi4_data *rmi4_data)
  3861. {
  3862. mutex_lock(&rmi4_data->rmi4_device_mutex);
  3863. if (rmi4_data->touch_stopped) {
  3864. dev_err(&rmi4_data->i2c_client->dev, "%s already power off\n",
  3865. __func__);
  3866. goto out;
  3867. }
  3868. disable_irq(rmi4_data->i2c_client->irq);
  3869. synaptics_rmi4_release_all_finger(rmi4_data);
  3870. rmi4_data->touch_stopped = true;
  3871. synaptics_power_ctrl(rmi4_data,false);
  3872. mdss_dsi_panel_touchsensing(false);
  3873. dev_dbg(&rmi4_data->i2c_client->dev, "%s\n", __func__);
  3874. out:
  3875. mutex_unlock(&rmi4_data->rmi4_device_mutex);
  3876. return 0;
  3877. }
  3878. static int synaptics_rmi4_start_device(struct synaptics_rmi4_data *rmi4_data)
  3879. {
  3880. int retval = 0;
  3881. mutex_lock(&rmi4_data->rmi4_device_mutex);
  3882. rmi4_data->current_page = MASK_8BIT; // added Page masking routine for ghost touch
  3883. if (!rmi4_data->touch_stopped) {
  3884. dev_err(&rmi4_data->i2c_client->dev, "%s already power on\n",
  3885. __func__);
  3886. goto out;
  3887. }
  3888. #if defined(CONFIG_TOUCHSCREEN_SYNAPTICS_PREVENT_HSYNC_LEAKAGE)
  3889. rmi4_data->board->hsync_onoff(false);
  3890. #endif
  3891. synaptics_power_ctrl(rmi4_data,true);
  3892. rmi4_data->touch_stopped = false;
  3893. mdss_dsi_panel_touchsensing(true);
  3894. msleep(SYNAPTICS_HW_RESET_TIME);
  3895. #if defined(CONFIG_TOUCHSCREEN_SYNAPTICS_PREVENT_HSYNC_LEAKAGE)
  3896. rmi4_data->board->hsync_onoff(true);
  3897. #endif
  3898. retval = synaptics_rmi4_reinit_device(rmi4_data);
  3899. if (retval < 0) {
  3900. dev_err(&rmi4_data->i2c_client->dev,
  3901. "%s: Failed to reinit device\n",
  3902. __func__);
  3903. }
  3904. enable_irq(rmi4_data->i2c_client->irq);
  3905. dev_dbg(&rmi4_data->i2c_client->dev, "%s\n", __func__);
  3906. out:
  3907. mutex_unlock(&rmi4_data->rmi4_device_mutex);
  3908. return retval;
  3909. }
  3910. #ifdef USE_OPEN_CLOSE
  3911. #ifdef USE_OPEN_DWORK
  3912. static void synaptics_rmi4_open_work(struct work_struct *work)
  3913. {
  3914. int retval;
  3915. struct synaptics_rmi4_data *rmi4_data =
  3916. container_of(work, struct synaptics_rmi4_data,
  3917. open_work.work);
  3918. retval = synaptics_rmi4_start_device(rmi4_data);
  3919. if (retval < 0)
  3920. dev_err(&rmi4_data->i2c_client->dev,
  3921. "%s: Failed to start device\n", __func__);
  3922. }
  3923. #endif
  3924. static int synaptics_rmi4_input_open(struct input_dev *dev)
  3925. {
  3926. struct synaptics_rmi4_data *rmi4_data = input_get_drvdata(dev);
  3927. int retval;
  3928. #ifdef TSP_INIT_COMPLETE
  3929. #if !defined(CONFIG_SEC_MELIUSCA_PROJECT)
  3930. retval = wait_for_completion_interruptible_timeout(&rmi4_data->init_done,
  3931. msecs_to_jiffies(60 * MSEC_PER_SEC));
  3932. #else
  3933. retval = wait_for_completion_interruptible_timeout(&rmi4_data->init_done,
  3934. msecs_to_jiffies(10 * MSEC_PER_SEC));
  3935. #endif
  3936. if (retval < 0) {
  3937. dev_err(&rmi4_data->i2c_client->dev,
  3938. "error while waiting for device to init (%d)\n", retval);
  3939. retval = -ENXIO;
  3940. goto err_open;
  3941. }
  3942. if (retval == 0) {
  3943. dev_err(&rmi4_data->i2c_client->dev,
  3944. "timedout while waiting for device to init\n");
  3945. retval = -ENXIO;
  3946. goto err_open;
  3947. }
  3948. #endif
  3949. dev_info(&rmi4_data->i2c_client->dev, "%s\n", __func__);
  3950. #ifdef USE_OPEN_DWORK
  3951. schedule_delayed_work(&rmi4_data->open_work,
  3952. msecs_to_jiffies(TOUCH_OPEN_DWORK_TIME));
  3953. #else
  3954. retval = synaptics_rmi4_start_device(rmi4_data);
  3955. if (retval < 0)
  3956. dev_err(&rmi4_data->i2c_client->dev,
  3957. "%s: Failed to start device\n", __func__);
  3958. #endif
  3959. return 0;
  3960. #ifdef TSP_INIT_COMPLETE
  3961. err_open:
  3962. return retval;
  3963. #endif
  3964. }
  3965. static void synaptics_rmi4_input_close(struct input_dev *dev)
  3966. {
  3967. struct synaptics_rmi4_data *rmi4_data = input_get_drvdata(dev);
  3968. dev_info(&rmi4_data->i2c_client->dev, "%s\n", __func__);
  3969. #ifdef TSP_PATTERN_TRACKING_METHOD
  3970. if(rmi4_data->ftouch_reboot == 1){
  3971. dev_info(&rmi4_data->i2c_client->dev, "%s skip close \n", __func__);
  3972. return;
  3973. }
  3974. #endif
  3975. #ifdef USE_OPEN_DWORK
  3976. cancel_delayed_work(&rmi4_data->open_work);
  3977. #endif
  3978. #ifdef TSP_PATTERN_TRACKING_METHOD
  3979. cancel_delayed_work(&rmi4_data->reboot_work);
  3980. #endif
  3981. synaptics_rmi4_stop_device(rmi4_data);
  3982. }
  3983. #endif
  3984. #ifdef CONFIG_PM
  3985. #ifdef CONFIG_HAS_EARLYSUSPEND
  3986. #define synaptics_rmi4_suspend NULL
  3987. #define synaptics_rmi4_resume NULL
  3988. /**
  3989. * synaptics_rmi4_early_suspend()
  3990. *
  3991. * Called by the kernel during the early suspend phase when the system
  3992. * enters suspend.
  3993. *
  3994. * This function calls synaptics_rmi4_sensor_sleep() to stop finger
  3995. * data acquisition and put the sensor to sleep.
  3996. */
  3997. static void synaptics_rmi4_early_suspend(struct early_suspend *h)
  3998. {
  3999. struct synaptics_rmi4_data *rmi4_data =
  4000. container_of(h, struct synaptics_rmi4_data,
  4001. early_suspend);
  4002. dev_info(&rmi4_data->i2c_client->dev, "%s\n", __func__);
  4003. if (rmi4_data->stay_awake) {
  4004. rmi4_data->staying_awake = true;
  4005. dev_info(&rmi4_data->i2c_client->dev, "%s : return due to staying_awake\n",
  4006. __func__);
  4007. return;
  4008. } else {
  4009. rmi4_data->staying_awake = false;
  4010. }
  4011. synaptics_rmi4_stop_device(rmi4_data);
  4012. return;
  4013. }
  4014. /**
  4015. * synaptics_rmi4_late_resume()
  4016. *
  4017. * Called by the kernel during the late resume phase when the system
  4018. * wakes up from suspend.
  4019. *
  4020. * This function goes through the sensor wake process if the system wakes
  4021. * up from early suspend (without going into suspend).
  4022. */
  4023. static void synaptics_rmi4_late_resume(struct early_suspend *h)
  4024. {
  4025. int retval = 0;
  4026. struct synaptics_rmi4_data *rmi4_data =
  4027. container_of(h, struct synaptics_rmi4_data,
  4028. early_suspend);
  4029. dev_info(&rmi4_data->i2c_client->dev, "%s\n", __func__);
  4030. if (rmi4_data->staying_awake) {
  4031. dev_info(&rmi4_data->i2c_client->dev, "%s : return due to staying_awake\n",
  4032. __func__);
  4033. return;
  4034. }
  4035. retval = synaptics_rmi4_start_device(rmi4_data);
  4036. if (retval < 0)
  4037. dev_err(&rmi4_data->i2c_client->dev,
  4038. "%s: Failed to start device\n", __func__);
  4039. return;
  4040. }
  4041. #else
  4042. /**
  4043. * synaptics_rmi4_suspend()
  4044. *
  4045. * Called by the kernel during the suspend phase when the system
  4046. * enters suspend.
  4047. *
  4048. * This function stops finger data acquisition and puts the sensor to
  4049. * sleep (if not already done so during the early suspend phase),
  4050. * disables the interrupt, and turns off the power to the sensor.
  4051. */
  4052. static int synaptics_rmi4_suspend(struct device *dev)
  4053. {
  4054. struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
  4055. dev_dbg(&rmi4_data->i2c_client->dev, "%s\n", __func__);
  4056. if (rmi4_data->staying_awake) {
  4057. dev_info(&rmi4_data->i2c_client->dev, "%s : return due to staying_awake\n",
  4058. __func__);
  4059. return 0;
  4060. }
  4061. mutex_lock(&rmi4_data->input_dev->mutex);
  4062. if (rmi4_data->input_dev->users)
  4063. synaptics_rmi4_stop_device(rmi4_data);
  4064. mutex_unlock(&rmi4_data->input_dev->mutex);
  4065. return 0;
  4066. }
  4067. /**
  4068. * synaptics_rmi4_resume()
  4069. *
  4070. * Called by the kernel during the resume phase when the system
  4071. * wakes up from suspend.
  4072. *
  4073. * This function turns on the power to the sensor, wakes the sensor
  4074. * from sleep, enables the interrupt, and starts finger data
  4075. * acquisition.
  4076. */
  4077. static int synaptics_rmi4_resume(struct device *dev)
  4078. {
  4079. int retval;
  4080. struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
  4081. dev_dbg(&rmi4_data->i2c_client->dev, "%s\n", __func__);
  4082. mutex_lock(&rmi4_data->input_dev->mutex);
  4083. if (rmi4_data->input_dev->users) {
  4084. retval = synaptics_rmi4_start_device(rmi4_data);
  4085. if (retval < 0)
  4086. dev_err(&rmi4_data->i2c_client->dev,
  4087. "%s: Failed to start device\n", __func__);
  4088. }
  4089. mutex_unlock(&rmi4_data->input_dev->mutex);
  4090. return 0;
  4091. }
  4092. #endif
  4093. static const struct dev_pm_ops synaptics_rmi4_dev_pm_ops = {
  4094. .suspend = synaptics_rmi4_suspend,
  4095. .resume = synaptics_rmi4_resume,
  4096. };
  4097. #endif
  4098. static const struct i2c_device_id synaptics_rmi4_id_table[] = {
  4099. {DRIVER_NAME, 0},
  4100. {},
  4101. };
  4102. MODULE_DEVICE_TABLE(i2c, synaptics_rmi4_id_table);
  4103. #ifdef CONFIG_OF
  4104. static struct of_device_id synaptics_match_table[] = {
  4105. { .compatible = "synaptics,rmi4-ts",},
  4106. { },
  4107. };
  4108. #else
  4109. #define synaptics_match_table NULL
  4110. #endif
  4111. static struct i2c_driver synaptics_rmi4_driver = {
  4112. .driver = {
  4113. .name = DRIVER_NAME,
  4114. .owner = THIS_MODULE,
  4115. .of_match_table = synaptics_match_table,
  4116. #ifdef CONFIG_PM
  4117. .pm = &synaptics_rmi4_dev_pm_ops,
  4118. #endif
  4119. },
  4120. .probe = synaptics_rmi4_probe,
  4121. .remove = __devexit_p(synaptics_rmi4_remove),
  4122. .id_table = synaptics_rmi4_id_table,
  4123. };
  4124. /**
  4125. * synaptics_rmi4_init()
  4126. *
  4127. * Called by the kernel during do_initcalls (if built-in)
  4128. * or when the driver is loaded (if a module).
  4129. *
  4130. * This function registers the driver to the I2C subsystem.
  4131. *
  4132. */
  4133. static int __init synaptics_rmi4_init(void)
  4134. {
  4135. printk(KERN_ERR "TSP %s: ln:%d\n", __func__, __LINE__);
  4136. return i2c_add_driver(&synaptics_rmi4_driver);
  4137. }
  4138. /**
  4139. * synaptics_rmi4_exit()
  4140. *
  4141. * Called by the kernel when the driver is unloaded.
  4142. *
  4143. * This funtion unregisters the driver from the I2C subsystem.
  4144. *
  4145. */
  4146. static void __exit synaptics_rmi4_exit(void)
  4147. {
  4148. i2c_del_driver(&synaptics_rmi4_driver);
  4149. }
  4150. module_init(synaptics_rmi4_init);
  4151. module_exit(synaptics_rmi4_exit);
  4152. MODULE_AUTHOR("Synaptics, Inc.");
  4153. MODULE_DESCRIPTION("Synaptics RMI4 I2C Touch Driver");
  4154. MODULE_LICENSE("GPL v2");
  4155. MODULE_VERSION(SYNAPTICS_RMI4_DRIVER_VERSION);