zinitix_bt532_ts.c 143 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330
  1. /*
  2. *
  3. * Zinitix bt532 touchscreen driver
  4. *
  5. * Copyright (C) 2013 Samsung Electronics Co.Ltd
  6. *
  7. * This software is licensed under the terms of the GNU General Public
  8. * License version 2, as published by the Free Software Foundation, and
  9. * may be copied, distributed, and modified under those terms.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. */
  17. #define TSP_VERBOSE_DEBUG
  18. #define SEC_FACTORY_TEST
  19. #if defined(CONFIG_SEC_MEGA23G_COMMON) || defined(CONFIG_SEC_MEGA2LTE_COMMON)
  20. #define SUPPORTED_TOUCH_KEY 1
  21. #define ZINITIX_NEW_TA_COVER_REGISTER_0x11F
  22. #define USE_ACTIVE_REPORT_RATE
  23. #else
  24. #define SUPPORTED_TOUCH_KEY 0
  25. #endif
  26. #define TSP_BOOSTER
  27. #include <linux/module.h>
  28. #include <linux/input.h>
  29. #include <linux/i2c.h>
  30. #include <linux/miscdevice.h>
  31. #include <linux/interrupt.h>
  32. #if defined(CONFIG_PM_RUNTIME)
  33. #include <linux/pm_runtime.h>
  34. #endif
  35. #include <linux/semaphore.h>
  36. #include <linux/timer.h>
  37. #include <linux/workqueue.h>
  38. #include <linux/slab.h>
  39. #include <linux/delay.h>
  40. #include <linux/gpio.h>
  41. #include <linux/uaccess.h>
  42. #include <linux/regulator/consumer.h>
  43. #include <zinitix_bt532_ts.h>
  44. #include <linux/input/mt.h>
  45. #include <linux/regulator/machine.h>
  46. #include <linux/of_device.h>
  47. #include <linux/of_gpio.h>
  48. #include <linux/of_irq.h>
  49. #include <asm/io.h>
  50. #include <linux/power_supply.h>
  51. #if defined(CONFIG_USB_SWITCH_TSU6721) || defined(CONFIG_USB_SWITCH_RT8973) || defined(CONFIG_SM5502_MUIC)
  52. #include <linux/i2c/tsu6721.h>
  53. #endif
  54. #ifdef CONFIG_MACH_PXA_SAMSUNG
  55. #include <linux/sec-common.h>
  56. #endif
  57. /* added header file */
  58. #if defined(CONFIG_SEC_MEGA23G_COMMON) || defined(CONFIG_SEC_MEGA2LTE_COMMON)
  59. #include "zinitix_touch_zxt_firmware_ZI012407.h"
  60. #elif defined(CONFIG_MACH_DEGASLTE_SBM)
  61. #include "zinitix_touch_zxt_firmware_ZI002516.h"
  62. #else
  63. #include "zinitix_touch_zxt_firmware_ZI002517.h"
  64. #endif
  65. #ifdef TSP_BOOSTER
  66. #include <linux/cpufreq.h>
  67. #define DVFS_STAGE_DUAL 2
  68. #define DVFS_STAGE_SINGLE 1
  69. #define DVFS_STAGE_NONE 0
  70. #define TOUCH_BOOSTER_OFF_TIME 300
  71. #define TOUCH_BOOSTER_CHG_TIME 200
  72. #endif
  73. #define NOT_SUPPORTED_TOUCH_DUMMY_KEY
  74. #define SUPPORTED_PALM_TOUCH
  75. extern char *saved_command_line;
  76. #define ZINITIX_DEBUG 0
  77. #ifdef SUPPORTED_PALM_TOUCH
  78. #define TOUCH_POINT_MODE 2
  79. #else
  80. #define TOUCH_POINT_MODE 0
  81. #endif
  82. #define MAX_SUPPORTED_FINGER_NUM 5 /* max 10 */
  83. #ifdef SUPPORTED_TOUCH_KEY
  84. #ifdef NOT_SUPPORTED_TOUCH_DUMMY_KEY
  85. #define MAX_SUPPORTED_BUTTON_NUM 2 /* max 8 */
  86. #define SUPPORTED_BUTTON_NUM 2
  87. #else
  88. #define MAX_SUPPORTED_BUTTON_NUM 2 /* max 8 */
  89. #define SUPPORTED_BUTTON_NUM 2
  90. #endif
  91. #endif
  92. #define TSP_HW_ID_INDEX_NULL 3
  93. /* Upgrade Method*/
  94. #define TOUCH_ONESHOT_UPGRADE 1
  95. /* if you use isp mode, you must add i2c device :
  96. name = "zinitix_isp" , addr 0x50*/
  97. /* resolution offset */
  98. #define ABS_PT_OFFSET (-1)
  99. #define TOUCH_FORCE_UPGRADE 1
  100. #define USE_CHECKSUM 1
  101. #if defined(CONFIG_SEC_MEGA23G_COMMON) || defined(CONFIG_SEC_MEGA2LTE_COMMON)
  102. #define CHECK_HWID 1
  103. #else
  104. #define CHECK_HWID 0
  105. #endif
  106. #define CHIP_OFF_DELAY 50 /*ms*/
  107. #define CHIP_ON_DELAY 15 /*ms*/
  108. #define FIRMWARE_ON_DELAY 40 /*ms*/
  109. #define DELAY_FOR_SIGNAL_DELAY 30 /*us*/
  110. #define DELAY_FOR_TRANSCATION 50
  111. #define DELAY_FOR_POST_TRANSCATION 10
  112. /* PMIC Regulator based supply to TSP */
  113. #define TSP_REGULATOR_SUPPLY 1
  114. /* gpio controlled LDO based supply to TSP */
  115. #define TSP_LDO_SUPPLY 0
  116. enum power_control {
  117. POWER_OFF,
  118. POWER_ON,
  119. POWER_ON_SEQUENCE,
  120. };
  121. /* Key Enum */
  122. enum key_event {
  123. ICON_BUTTON_UNCHANGE,
  124. ICON_BUTTON_DOWN,
  125. ICON_BUTTON_UP,
  126. };
  127. /* ESD Protection */
  128. /*second : if 0, no use. if you have to use, 3 is recommended*/
  129. #define ESD_TIMER_INTERVAL 1
  130. #define SCAN_RATE_HZ 100
  131. #define CHECK_ESD_TIMER 3
  132. /*Test Mode (Monitoring Raw Data) */
  133. #if defined(CONFIG_SEC_MEGA23G_COMMON) || defined(CONFIG_SEC_MEGA2LTE_COMMON)
  134. #define SEC_DND_SHIFT_VALUE 2
  135. #define SEC_DND_N_COUNT 10
  136. #define SEC_DND_U_COUNT 2
  137. #define SEC_DND_FREQUENCY 116
  138. #define SEC_PDND_N_COUNT 16
  139. #define SEC_PDND_U_COUNT 20
  140. #define SEC_PDND_FREQUENCY 119
  141. #else
  142. #define SEC_DND_SHIFT_VALUE 3
  143. #define SEC_DND_N_COUNT 10
  144. #define SEC_DND_U_COUNT 2
  145. #define SEC_DND_FREQUENCY 99 /* 200khz */
  146. #define SEC_PDND_N_COUNT 16
  147. #define SEC_PDND_U_COUNT 14
  148. #define SEC_PDND_FREQUENCY 66
  149. #endif
  150. #define MAX_RAW_DATA_SZ 576 /* 32x18 */
  151. #define MAX_TRAW_DATA_SZ \
  152. (MAX_RAW_DATA_SZ + 4*MAX_SUPPORTED_FINGER_NUM + 2)
  153. /* preriod raw data interval */
  154. #define RAWDATA_DELAY_FOR_HOST 100
  155. struct raw_ioctl {
  156. int sz;
  157. u8 *buf;
  158. };
  159. struct reg_ioctl {
  160. int addr;
  161. int *val;
  162. };
  163. #define TOUCH_SEC_MODE 48
  164. #define TOUCH_REF_MODE 10
  165. #define TOUCH_NORMAL_MODE 5
  166. #define TOUCH_DELTA_MODE 3
  167. #define TOUCH_DND_MODE 6
  168. #define TOUCH_PDND_MODE 11
  169. /* Other Things */
  170. #define INIT_RETRY_CNT 1
  171. #define I2C_SUCCESS 0
  172. #define I2C_FAIL 1
  173. /*---------------------------------------------------------------------*/
  174. /* Register Map*/
  175. #define BT532_SWRESET_CMD 0x0000
  176. #define BT532_WAKEUP_CMD 0x0001
  177. #define BT532_IDLE_CMD 0x0004
  178. #define BT532_SLEEP_CMD 0x0005
  179. #define BT532_CLEAR_INT_STATUS_CMD 0x0003
  180. #define BT532_CALIBRATE_CMD 0x0006
  181. #define BT532_SAVE_STATUS_CMD 0x0007
  182. #define BT532_SAVE_CALIBRATION_CMD 0x0008
  183. #define BT532_RECALL_FACTORY_CMD 0x000f
  184. #define BT532_THRESHOLD 0x0020
  185. #define BT532_DEBUG_REG 0x0115 /* 0~7 */
  186. #define BT532_TOUCH_MODE 0x0010
  187. #define BT532_CHIP_REVISION 0x0011
  188. #define BT532_FIRMWARE_VERSION 0x0012
  189. #define BT532_MINOR_FW_VERSION 0x0121
  190. #define BT532_VENDOR_ID 0x001C
  191. #define BT532_HW_ID 0x0014
  192. #define BT532_DATA_VERSION_REG 0x0013
  193. #define BT532_SUPPORTED_FINGER_NUM 0x0015
  194. #define BT532_EEPROM_INFO 0x0018
  195. #define BT532_INITIAL_TOUCH_MODE 0x0019
  196. #define BT532_TOTAL_NUMBER_OF_X 0x0060
  197. #define BT532_TOTAL_NUMBER_OF_Y 0x0061
  198. #define BT532_DELAY_RAW_FOR_HOST 0x007f
  199. #define BT532_BUTTON_SUPPORTED_NUM 0x00B0
  200. #define BT532_BUTTON_SENSITIVITY 0x00B2
  201. #define BT532_DUMMY_BUTTON_SENSITIVITY 0X00C8
  202. #define BT532_X_RESOLUTION 0x00C0
  203. #define BT532_Y_RESOLUTION 0x00C1
  204. #define BT532_POINT_STATUS_REG 0x0080
  205. #define BT532_ICON_STATUS_REG 0x00AA
  206. #define BT532_DND_SHIFT_VALUE 0x012B
  207. #define BT532_AFE_FREQUENCY 0x0100
  208. #define BT532_DND_N_COUNT 0x0122
  209. #define BT532_DND_U_COUNT 0x0135
  210. #define BT532_RAWDATA_REG 0x0200
  211. #define BT532_EEPROM_INFO_REG 0x0018
  212. #define BT532_INT_ENABLE_FLAG 0x00f0
  213. #define BT532_PERIODICAL_INTERRUPT_INTERVAL 0x00f1
  214. #define BT532_BTN_WIDTH 0x016d
  215. #define BT532_CHECKSUM_RESULT 0x012c
  216. #define BT532_INIT_FLASH 0x01d0
  217. #define BT532_WRITE_FLASH 0x01d1
  218. #define BT532_READ_FLASH 0x01d2
  219. #define ZINITIX_INTERNAL_FLAG_03 0x011f
  220. /* Interrupt & status register flag bit
  221. -------------------------------------------------
  222. */
  223. #define BIT_PT_CNT_CHANGE 0
  224. #define BIT_DOWN 1
  225. #define BIT_MOVE 2
  226. #define BIT_UP 3
  227. #define BIT_PALM 4
  228. #define BIT_PALM_REJECT 5
  229. #define RESERVED_0 6
  230. #define RESERVED_1 7
  231. #define BIT_WEIGHT_CHANGE 8
  232. #define BIT_PT_NO_CHANGE 9
  233. #define BIT_REJECT 10
  234. #define BIT_PT_EXIST 11
  235. #define RESERVED_2 12
  236. #define BIT_MUST_ZERO 13
  237. #define BIT_DEBUG 14
  238. #define BIT_ICON_EVENT 15
  239. /* button */
  240. #define BIT_O_ICON0_DOWN 0
  241. #define BIT_O_ICON1_DOWN 1
  242. #define BIT_O_ICON2_DOWN 2
  243. #define BIT_O_ICON3_DOWN 3
  244. #define BIT_O_ICON4_DOWN 4
  245. #define BIT_O_ICON5_DOWN 5
  246. #define BIT_O_ICON6_DOWN 6
  247. #define BIT_O_ICON7_DOWN 7
  248. #define BIT_O_ICON0_UP 8
  249. #define BIT_O_ICON1_UP 9
  250. #define BIT_O_ICON2_UP 10
  251. #define BIT_O_ICON3_UP 11
  252. #define BIT_O_ICON4_UP 12
  253. #define BIT_O_ICON5_UP 13
  254. #define BIT_O_ICON6_UP 14
  255. #define BIT_O_ICON7_UP 15
  256. #define SUB_BIT_EXIST 0
  257. #define SUB_BIT_DOWN 1
  258. #define SUB_BIT_MOVE 2
  259. #define SUB_BIT_UP 3
  260. #define SUB_BIT_UPDATE 4
  261. #define SUB_BIT_WAIT 5
  262. #define zinitix_bit_set(val, n) ((val) &= ~(1<<(n)), (val) |= (1<<(n)))
  263. #define zinitix_bit_clr(val, n) ((val) &= ~(1<<(n)))
  264. #define zinitix_bit_test(val, n) ((val) & (1<<(n)))
  265. #define zinitix_swap_v(a, b, t) ((t) = (a), (a) = (b), (b) = (t))
  266. #define zinitix_swap_16(s) (((((s) & 0xff) << 8) | (((s) >> 8) & 0xff)))
  267. #ifdef CONFIG_SAMSUNG_LPM_MODE
  268. extern int poweroff_charging;
  269. #endif
  270. /* end header file */
  271. #ifdef SEC_FACTORY_TEST
  272. /* Touch Screen */
  273. #define TSP_CMD_STR_LEN 32
  274. #define TSP_CMD_RESULT_STR_LEN 512
  275. #define TSP_CMD_PARAM_NUM 8
  276. #define TSP_CMD_Y_NUM 18
  277. #define TSP_CMD_X_NUM 30
  278. #define TSP_CMD_NODE_NUM (TSP_CMD_Y_NUM * TSP_CMD_X_NUM)
  279. #define tostring(x) #x
  280. struct tsp_factory_info {
  281. struct list_head cmd_list_head;
  282. char cmd[TSP_CMD_STR_LEN];
  283. char cmd_param[TSP_CMD_PARAM_NUM];
  284. char cmd_result[TSP_CMD_RESULT_STR_LEN];
  285. char cmd_buff[TSP_CMD_RESULT_STR_LEN];
  286. struct mutex cmd_lock;
  287. bool cmd_is_running;
  288. u8 cmd_state;
  289. };
  290. struct tsp_raw_data {
  291. u16 ref_data[TSP_CMD_NODE_NUM];
  292. u16 pref_data[TSP_CMD_NODE_NUM];
  293. /*s16 scantime_data[TSP_CMD_NODE_NUM]; */
  294. s16 delta_data[TSP_CMD_NODE_NUM];
  295. };
  296. enum {
  297. WAITING = 0,
  298. RUNNING,
  299. OK,
  300. FAIL,
  301. NOT_APPLICABLE,
  302. };
  303. struct tsp_cmd {
  304. struct list_head list;
  305. const char *cmd_name;
  306. void (*cmd_func)(void *device_data);
  307. };
  308. static void fw_update(void *device_data);
  309. static void get_fw_ver_bin(void *device_data);
  310. static void get_fw_ver_ic(void *device_data);
  311. static void get_threshold(void *device_data);
  312. static void module_off_master(void *device_data);
  313. static void module_on_master(void *device_data);
  314. static void module_off_slave(void *device_data);
  315. static void module_on_slave(void *device_data);
  316. static void get_chip_vendor(void *device_data);
  317. static void get_chip_name(void *device_data);
  318. static void get_x_num(void *device_data);
  319. static void get_y_num(void *device_data);
  320. static void not_support_cmd(void *device_data);
  321. /* Vendor dependant command */
  322. static void run_reference_read(void *device_data);
  323. static void run_reference_PDiff(void *device_data);
  324. static void get_reference(void *device_data);
  325. static void run_preference_read(void *device_data);
  326. static void get_preference(void *device_data);
  327. /*
  328. static void run_scantime_read(void *device_data);
  329. static void get_scantime(void *device_data);
  330. */
  331. static void run_delta_read(void *device_data);
  332. static void get_delta(void *device_data);
  333. static void clear_cover_mode(void *device_data);
  334. static void get_module_vendor(void *device_data);
  335. static void get_config_ver(void *device_data);
  336. #if defined(USE_ACTIVE_REPORT_RATE)
  337. static void report_rate(void *device_data);
  338. #endif
  339. #define TSP_CMD(name, func) .cmd_name = name, .cmd_func = func
  340. #if !defined(CONFIG_SEC_DEGAS_PROJECT)
  341. u32 config_version;
  342. #else
  343. #define CONFIG_DATE "0603"
  344. #endif
  345. static struct tsp_cmd tsp_cmds[] = {
  346. {TSP_CMD("fw_update", fw_update),},
  347. {TSP_CMD("get_fw_ver_bin", get_fw_ver_bin),},
  348. {TSP_CMD("get_fw_ver_ic", get_fw_ver_ic),},
  349. {TSP_CMD("get_threshold", get_threshold),},
  350. {TSP_CMD("module_off_master", module_off_master),},
  351. {TSP_CMD("module_on_master", module_on_master),},
  352. {TSP_CMD("module_off_slave", module_off_slave),},
  353. {TSP_CMD("module_on_slave", module_on_slave),},
  354. {TSP_CMD("get_module_vendor", get_module_vendor),},
  355. {TSP_CMD("get_chip_vendor", get_chip_vendor),},
  356. {TSP_CMD("get_chip_name", get_chip_name),},
  357. {TSP_CMD("get_x_num", get_x_num),},
  358. {TSP_CMD("get_y_num", get_y_num),},
  359. /* vendor dependant command */
  360. {TSP_CMD("run_reference_read", run_reference_read),},
  361. {TSP_CMD("run_reference_diff", run_reference_PDiff),},
  362. {TSP_CMD("get_reference", get_reference),},
  363. {TSP_CMD("run_dnd_read", run_preference_read),},
  364. {TSP_CMD("get_dnd", get_preference),},
  365. /*
  366. {TSP_CMD("run_scantime_read", run_scantime_read),},
  367. {TSP_CMD("get_scantime", get_scantime),},
  368. */
  369. {TSP_CMD("run_delta_read", run_delta_read),},
  370. {TSP_CMD("get_delta", get_delta),},
  371. {TSP_CMD("get_config_ver", get_config_ver),},
  372. {TSP_CMD("clear_cover_mode", clear_cover_mode),},
  373. #if defined(USE_ACTIVE_REPORT_RATE)
  374. {TSP_CMD("report_rate", report_rate),},
  375. #endif
  376. {TSP_CMD("not_support_cmd", not_support_cmd),},
  377. };
  378. #if 0
  379. #ifdef SUPPORTED_TOUCH_KEY
  380. /* Touch Key */
  381. static ssize_t touchkey_threshold(struct device *dev,
  382. struct device_attribute *attr, char *buf);
  383. static ssize_t touch_sensitivity(struct device *dev,
  384. struct device_attribute *attr, char *buf);
  385. static ssize_t touchkey_back(struct device *dev,
  386. struct device_attribute *attr, char *buf);
  387. static ssize_t touchkey_menu(struct device *dev,
  388. struct device_attribute *attr, char *buf);
  389. static ssize_t autocal_stat(struct device *dev,
  390. struct device_attribute *attr, char *buf);
  391. static ssize_t touchkey_raw_back(struct device *dev,
  392. struct device_attribute *attr, char *buf);
  393. static ssize_t touchkey_raw_menu(struct device *dev,
  394. struct device_attribute *attr, char *buf);
  395. static ssize_t touchkey_idac_back(struct device *dev,
  396. struct device_attribute *attr, char *buf);
  397. static ssize_t touchkey_idac_menu(struct device *dev,
  398. struct device_attribute *attr, char *buf);
  399. #endif
  400. #endif
  401. #endif
  402. #define TSP_NORMAL_EVENT_MSG 1
  403. static int m_ts_debug_mode = ZINITIX_DEBUG;
  404. static bool ta_connected =0;
  405. //void (*tsp_charger_status_cb)(int);
  406. #define COVER_OPEN 0
  407. #define COVER_CLOSED 3
  408. static int g_cover_state;
  409. static u16 g_internal_flag_03 = 1;
  410. static u16 m_optional_mode = 0;
  411. static u16 m_prev_optional_mode = 0;
  412. #if ESD_TIMER_INTERVAL
  413. static struct workqueue_struct *esd_tmr_workqueue;
  414. #endif
  415. struct coord {
  416. u16 x;
  417. u16 y;
  418. u8 width;
  419. u8 sub_status;
  420. #if (TOUCH_POINT_MODE == 2)
  421. u8 minor_width;
  422. u8 angle;
  423. #endif
  424. };
  425. struct point_info {
  426. u16 status;
  427. #if (TOUCH_POINT_MODE == 1)
  428. u16 event_flag;
  429. #else
  430. u8 finger_cnt;
  431. u8 time_stamp;
  432. #endif
  433. struct coord coord[MAX_SUPPORTED_FINGER_NUM];
  434. };
  435. #define TOUCH_V_FLIP 0x01
  436. #define TOUCH_H_FLIP 0x02
  437. #define TOUCH_XY_SWAP 0x04
  438. struct capa_info {
  439. u16 vendor_id;
  440. u16 ic_revision;
  441. u16 fw_version;
  442. u16 fw_minor_version;
  443. u16 reg_data_version;
  444. u16 threshold;
  445. u16 key_threshold;
  446. u16 dummy_threshold;
  447. u32 ic_fw_size;
  448. u32 MaxX;
  449. u32 MaxY;
  450. u32 MinX;
  451. u32 MinY;
  452. u8 gesture_support;
  453. u16 multi_fingers;
  454. u16 button_num;
  455. u16 ic_int_mask;
  456. u16 x_node_num;
  457. u16 y_node_num;
  458. u16 total_node_num;
  459. u16 hw_id;
  460. u16 afe_frequency;
  461. u16 shift_value;
  462. u16 N_cnt;
  463. u16 u_cnt;
  464. };
  465. enum work_state {
  466. NOTHING = 0,
  467. NORMAL,
  468. ESD_TIMER,
  469. SUSPEND,
  470. RESUME,
  471. UPGRADE,
  472. REMOVE,
  473. SET_MODE,
  474. HW_CALIBRAION,
  475. RAW_DATA,
  476. PROBE,
  477. };
  478. enum {
  479. BUILT_IN = 0,
  480. UMS,
  481. REQ_FW,
  482. };
  483. struct bt532_ts_info {
  484. struct i2c_client *client;
  485. struct input_dev *input_dev;
  486. struct bt532_ts_platform_data *pdata;
  487. char phys[32];
  488. /*struct task_struct *task;*/
  489. /*wait_queue_head_t wait;*/
  490. /*struct semaphore update_lock;*/
  491. /*u32 i2c_dev_addr;*/
  492. struct capa_info cap_info;
  493. struct point_info touch_info;
  494. struct point_info reported_touch_info;
  495. u16 icon_event_reg;
  496. u16 prev_icon_event;
  497. /*u16 event_type;*/
  498. int irq;
  499. u8 button[MAX_SUPPORTED_BUTTON_NUM];
  500. u8 work_state;
  501. struct semaphore work_lock;
  502. /*u16 debug_reg[8];*/
  503. #if ESD_TIMER_INTERVAL
  504. struct work_struct tmr_work;
  505. struct timer_list esd_timeout_tmr;
  506. struct timer_list *p_esd_timeout_tmr;
  507. spinlock_t lock;
  508. #endif
  509. struct semaphore raw_data_lock;
  510. u16 touch_mode;
  511. s16 cur_data[MAX_TRAW_DATA_SZ];
  512. u8 update;
  513. #ifdef SEC_FACTORY_TEST
  514. struct tsp_factory_info *factory_info;
  515. struct tsp_raw_data *raw_data;
  516. #endif
  517. u16 dnd_data[MAX_RAW_DATA_SZ];
  518. s16 ref_data[MAX_RAW_DATA_SZ];
  519. s16 ref_scale_factor;
  520. s16 ref_btn_option;
  521. s16 hdiff_max_x;
  522. s16 hdiff_max_y;
  523. s16 hdiff_max_val;
  524. s16 hdiff_min_x;
  525. s16 hdiff_min_y;
  526. s16 hdiff_min_val;
  527. s16 vdiff_max_x;
  528. s16 vdiff_max_y;
  529. s16 vdiff_max_val;
  530. s16 vdiff_min_x;
  531. s16 vdiff_min_y;
  532. s16 vdiff_min_val;
  533. struct regulator *vddo_vreg;
  534. u8 tsp_type_hw;
  535. struct regulator *vdd_en;
  536. bool device_enabled;
  537. #ifdef TSP_BOOSTER
  538. u8 touch_pressed_num;
  539. bool dvfs_lock_status;
  540. struct delayed_work work_dvfs_off;
  541. struct delayed_work work_dvfs_chg;
  542. struct mutex dvfs_lock;
  543. int dvfs_old_status;
  544. unsigned char boost_level;
  545. int dvfs_freq;
  546. #endif
  547. };
  548. /* Dummy touchkey code */
  549. #define KEY_DUMMY_HOME1 249
  550. #define KEY_DUMMY_HOME2 250
  551. #define KEY_DUMMY_MENU 251
  552. #define KEY_DUMMY_HOME 252
  553. #define KEY_DUMMY_BACK 253
  554. /*<= you must set key button mapping*/
  555. #ifdef NOT_SUPPORTED_TOUCH_DUMMY_KEY
  556. u32 BUTTON_MAPPING_KEY[MAX_SUPPORTED_BUTTON_NUM] = {
  557. KEY_RECENT, KEY_BACK};
  558. #else
  559. u32 BUTTON_MAPPING_KEY[MAX_SUPPORTED_BUTTON_NUM] = {
  560. KEY_DUMMY_MENU, KEY_RECENT,// KEY_DUMMY_HOME1,
  561. /*KEY_DUMMY_HOME2,*/ KEY_BACK, KEY_DUMMY_BACK};
  562. #endif
  563. /* VASTA SPEC */
  564. const u16 dnd_v_diff_00[29][18]={
  565. {3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500},
  566. {3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500},
  567. {3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500},
  568. {3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500},
  569. {3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500},
  570. {3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500},
  571. {3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500},
  572. {3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500},
  573. {3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500},
  574. {3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500},
  575. {3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500},
  576. {3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500},
  577. {3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500},
  578. {3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500},
  579. {3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500},
  580. {3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500},
  581. {3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500},
  582. {3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500},
  583. {3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500},
  584. {3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500},
  585. {3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500},
  586. {3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500},
  587. {3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500},
  588. {3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500},
  589. {3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500},
  590. {3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500},
  591. {3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500},
  592. {3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500, 3500},
  593. { 0, 0, 0, 10000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10000, 0, 0, 0}
  594. };
  595. const u16 dnd_h_diff_00[29][17]={
  596. {3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000},
  597. {3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000},
  598. {3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000},
  599. {3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000},
  600. {3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000},
  601. {3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000},
  602. {3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000},
  603. {3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000},
  604. {3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000},
  605. {3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000},
  606. {3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000},
  607. {3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000},
  608. {3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000},
  609. {3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000},
  610. {3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000},
  611. {3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000},
  612. {3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000},
  613. {3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000},
  614. {3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000},
  615. {3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000},
  616. {3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000},
  617. {3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000},
  618. {3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000},
  619. {3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000},
  620. {3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000},
  621. {3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000},
  622. {3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000},
  623. {3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000},
  624. {3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000}
  625. };
  626. /* define i2c sub functions*/
  627. static inline s32 read_data(struct i2c_client *client,
  628. u16 reg, u8 *values, u16 length)
  629. {
  630. s32 ret;
  631. int count = 0;
  632. retry:
  633. /* select register*/
  634. ret = i2c_master_send(client , (u8 *)&reg , 2);
  635. if (ret < 0) {
  636. mdelay(1);
  637. if (++count < 8)
  638. goto retry;
  639. return ret;
  640. }
  641. /* for setup tx transaction. */
  642. udelay(DELAY_FOR_TRANSCATION);
  643. ret = i2c_master_recv(client , values , length);
  644. if (ret < 0)
  645. return ret;
  646. udelay(DELAY_FOR_POST_TRANSCATION);
  647. return length;
  648. }
  649. static inline s32 write_data(struct i2c_client *client,
  650. u16 reg, u8 *values, u16 length)
  651. {
  652. s32 ret;
  653. int count = 0;
  654. u8 pkt[10]; /* max packet */
  655. pkt[0] = (reg) & 0xff; /* reg addr */
  656. pkt[1] = (reg >> 8)&0xff;
  657. memcpy((u8 *)&pkt[2], values, length);
  658. retry:
  659. ret = i2c_master_send(client , pkt , length + 2);
  660. if (ret < 0) {
  661. mdelay(1);
  662. if (++count < 8)
  663. goto retry;
  664. return ret;
  665. }
  666. udelay(DELAY_FOR_POST_TRANSCATION);
  667. return length;
  668. }
  669. static inline s32 write_reg(struct i2c_client *client, u16 reg, u16 value)
  670. {
  671. if (write_data(client, reg, (u8 *)&value, 2) < 0)
  672. return I2C_FAIL;
  673. return I2C_SUCCESS;
  674. }
  675. static inline s32 write_cmd(struct i2c_client *client, u16 reg)
  676. {
  677. s32 ret;
  678. int count = 0;
  679. retry:
  680. ret = i2c_master_send(client , (u8 *)&reg , 2);
  681. if (ret < 0) {
  682. mdelay(1);
  683. if (++count < 8)
  684. goto retry;
  685. return ret;
  686. }
  687. udelay(DELAY_FOR_POST_TRANSCATION);
  688. return I2C_SUCCESS;
  689. }
  690. static inline s32 read_raw_data(struct i2c_client *client,
  691. u16 reg, u8 *values, u16 length)
  692. {
  693. s32 ret;
  694. int count = 0;
  695. retry:
  696. /* select register */
  697. ret = i2c_master_send(client , (u8 *)&reg , 2);
  698. if (ret < 0) {
  699. mdelay(1);
  700. if (++count < 8)
  701. goto retry;
  702. return ret;
  703. }
  704. /* for setup tx transaction. */
  705. udelay(200);
  706. ret = i2c_master_recv(client , values , length);
  707. if (ret < 0)
  708. return ret;
  709. udelay(DELAY_FOR_POST_TRANSCATION);
  710. return length;
  711. }
  712. static inline s32 read_firmware_data(struct i2c_client *client,
  713. u16 addr, u8 *values, u16 length)
  714. {
  715. s32 ret;
  716. /* select register*/
  717. ret = i2c_master_send(client , (u8 *)&addr , 2);
  718. if (ret < 0)
  719. return ret;
  720. /* for setup tx transaction. */
  721. mdelay(1);
  722. ret = i2c_master_recv(client , values , length);
  723. if (ret < 0)
  724. return ret;
  725. udelay(DELAY_FOR_POST_TRANSCATION);
  726. return length;
  727. }
  728. static bool bt532_power_control(struct bt532_ts_info *info, u8 ctl);
  729. static bool init_touch(struct bt532_ts_info *info);
  730. static bool mini_init_touch(struct bt532_ts_info *info);
  731. static void clear_report_data(struct bt532_ts_info *info);
  732. #if ESD_TIMER_INTERVAL
  733. static void esd_timer_start(u16 sec, struct bt532_ts_info *info);
  734. static void esd_timer_stop(struct bt532_ts_info *info);
  735. static void esd_timer_init(struct bt532_ts_info *info);
  736. static void esd_timeout_handler(unsigned long data);
  737. #endif
  738. static long ts_misc_fops_ioctl(struct file *filp, unsigned int cmd,
  739. unsigned long arg);
  740. static int ts_misc_fops_open(struct inode *inode, struct file *filp);
  741. static int ts_misc_fops_close(struct inode *inode, struct file *filp);
  742. static const struct file_operations ts_misc_fops = {
  743. .owner = THIS_MODULE,
  744. .open = ts_misc_fops_open,
  745. .release = ts_misc_fops_close,
  746. .unlocked_ioctl = ts_misc_fops_ioctl,
  747. };
  748. static struct miscdevice touch_misc_device = {
  749. .minor = MISC_DYNAMIC_MINOR,
  750. .name = "zinitix_touch_misc",
  751. .fops = &ts_misc_fops,
  752. };
  753. #define TOUCH_IOCTL_BASE 0xbc
  754. #define TOUCH_IOCTL_GET_DEBUGMSG_STATE _IOW(TOUCH_IOCTL_BASE, 0, int)
  755. #define TOUCH_IOCTL_SET_DEBUGMSG_STATE _IOW(TOUCH_IOCTL_BASE, 1, int)
  756. #define TOUCH_IOCTL_GET_CHIP_REVISION _IOW(TOUCH_IOCTL_BASE, 2, int)
  757. #define TOUCH_IOCTL_GET_FW_VERSION _IOW(TOUCH_IOCTL_BASE, 3, int)
  758. #define TOUCH_IOCTL_GET_REG_DATA_VERSION _IOW(TOUCH_IOCTL_BASE, 4, int)
  759. #define TOUCH_IOCTL_VARIFY_UPGRADE_SIZE _IOW(TOUCH_IOCTL_BASE, 5, int)
  760. #define TOUCH_IOCTL_VARIFY_UPGRADE_DATA _IOW(TOUCH_IOCTL_BASE, 6, int)
  761. #define TOUCH_IOCTL_START_UPGRADE _IOW(TOUCH_IOCTL_BASE, 7, int)
  762. #define TOUCH_IOCTL_GET_X_NODE_NUM _IOW(TOUCH_IOCTL_BASE, 8, int)
  763. #define TOUCH_IOCTL_GET_Y_NODE_NUM _IOW(TOUCH_IOCTL_BASE, 9, int)
  764. #define TOUCH_IOCTL_GET_TOTAL_NODE_NUM _IOW(TOUCH_IOCTL_BASE, 10, int)
  765. #define TOUCH_IOCTL_SET_RAW_DATA_MODE _IOW(TOUCH_IOCTL_BASE, 11, int)
  766. #define TOUCH_IOCTL_GET_RAW_DATA _IOW(TOUCH_IOCTL_BASE, 12, int)
  767. #define TOUCH_IOCTL_GET_X_RESOLUTION _IOW(TOUCH_IOCTL_BASE, 13, int)
  768. #define TOUCH_IOCTL_GET_Y_RESOLUTION _IOW(TOUCH_IOCTL_BASE, 14, int)
  769. #define TOUCH_IOCTL_HW_CALIBRAION _IOW(TOUCH_IOCTL_BASE, 15, int)
  770. #define TOUCH_IOCTL_GET_REG _IOW(TOUCH_IOCTL_BASE, 16, int)
  771. #define TOUCH_IOCTL_SET_REG _IOW(TOUCH_IOCTL_BASE, 17, int)
  772. #define TOUCH_IOCTL_SEND_SAVE_STATUS _IOW(TOUCH_IOCTL_BASE, 18, int)
  773. #define TOUCH_IOCTL_DONOT_TOUCH_EVENT _IOW(TOUCH_IOCTL_BASE, 19, int)
  774. struct bt532_ts_info *misc_info;
  775. static void bt532_firmware_check(struct bt532_ts_platform_data *pdata)
  776. {
  777. #if defined(CONFIG_SEC_DEGAS_PROJECT)
  778. misc_info->tsp_type_hw = TSP_HW_ID_INDEX_NULL; //HW_ID 3
  779. gpio_tlmm_config(GPIO_CFG(pdata->tsp_vendor1, 0,
  780. GPIO_CFG_INPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), 1);
  781. gpio_tlmm_config(GPIO_CFG(pdata->tsp_vendor2, 0,
  782. GPIO_CFG_INPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), 1);
  783. printk("gpio_get_value(TSP_ID_1:gpio%d)=%d, gpio_get_value(TSP_ID_2:gpio%d)=%d\n",\
  784. pdata->tsp_vendor1, gpio_get_value(pdata->tsp_vendor1), pdata->tsp_vendor2, gpio_get_value(pdata->tsp_vendor2));
  785. if(!gpio_get_value(pdata->tsp_vendor1))
  786. zinitix_bit_clr(misc_info->tsp_type_hw,0); //HW_ID 2
  787. if(!gpio_get_value(pdata->tsp_vendor2))
  788. zinitix_bit_clr(misc_info->tsp_type_hw,1); //HW_ID 0
  789. zinitix_printk("%s %d\n",__func__,misc_info->tsp_type_hw);
  790. #else
  791. return;
  792. #endif
  793. }
  794. static void bt532_set_optional_mode(struct bt532_ts_info *info, bool force)
  795. {
  796. u16 reg_val;
  797. if(m_prev_optional_mode == m_optional_mode && !force)
  798. return;
  799. reg_val = g_internal_flag_03 | m_optional_mode;
  800. if(write_reg(info->client, ZINITIX_INTERNAL_FLAG_03, reg_val)==I2C_SUCCESS){
  801. m_prev_optional_mode = m_optional_mode;
  802. }
  803. }
  804. static bool get_raw_data(struct bt532_ts_info *info, u8 *buff, int skip_cnt)
  805. {
  806. struct i2c_client *client = info->client;
  807. struct bt532_ts_platform_data *pdata = info->pdata;
  808. u32 total_node = info->cap_info.total_node_num;
  809. u32 sz;
  810. int i;
  811. disable_irq(info->irq);
  812. down(&info->work_lock);
  813. if (info->work_state != NOTHING) {
  814. printk(KERN_INFO "other process occupied.. (%d)\n",
  815. info->work_state);
  816. enable_irq(info->irq);
  817. up(&info->work_lock);
  818. return false;
  819. }
  820. info->work_state = RAW_DATA;
  821. for (i = 0; i < skip_cnt; i++) {
  822. while (gpio_get_value(pdata->gpio_int))
  823. msleep(1);
  824. write_cmd(client, BT532_CLEAR_INT_STATUS_CMD);
  825. msleep(1);
  826. }
  827. zinitix_debug_msg("read raw data\r\n");
  828. sz = total_node*2;
  829. while (gpio_get_value(pdata->gpio_int))
  830. msleep(1);
  831. if (read_raw_data(client, BT532_RAWDATA_REG, (char *)buff, sz) < 0) {
  832. zinitix_printk("error : read zinitix tc raw data\n");
  833. info->work_state = NOTHING;
  834. enable_irq(info->irq);
  835. up(&info->work_lock);
  836. return false;
  837. }
  838. write_cmd(client, BT532_CLEAR_INT_STATUS_CMD);
  839. info->work_state = NOTHING;
  840. enable_irq(info->irq);
  841. up(&info->work_lock);
  842. return true;
  843. }
  844. static bool ts_get_raw_data(struct bt532_ts_info *info)
  845. {
  846. struct i2c_client *client = info->client;
  847. u32 total_node = info->cap_info.total_node_num;
  848. u32 sz;
  849. if (down_trylock(&info->raw_data_lock)) {
  850. dev_err(&client->dev, "Failed to occupy sema\n");
  851. info->touch_info.status = 0;
  852. return true;
  853. }
  854. sz = total_node * 2 + sizeof(struct point_info);
  855. if (read_raw_data(info->client, BT532_RAWDATA_REG,
  856. (char *)info->cur_data, sz) < 0) {
  857. dev_err(&client->dev, "Failed to read raw data\n");
  858. up(&info->raw_data_lock);
  859. return false;
  860. }
  861. info->update = 1;
  862. memcpy((u8 *)(&info->touch_info),
  863. (u8 *)&info->cur_data[total_node],
  864. sizeof(struct point_info));
  865. up(&info->raw_data_lock);
  866. return true;
  867. }
  868. #if defined(USE_ACTIVE_REPORT_RATE)
  869. #define BT532_LPM_INTERRUPT_INTERVAL 0x0142
  870. #define BT532_LPM_PERIOD_DELAY 0x00e2
  871. #define BT532_LPM_STATE 0x007e
  872. #define DEF_TS_LPM_LEVEL_DEFAULT 3
  873. static int g_prev_lpm_level = DEF_TS_LPM_LEVEL_DEFAULT;
  874. static int g_lpm_level = DEF_TS_LPM_LEVEL_DEFAULT;
  875. static void ts_lpm_set(int level)
  876. {
  877. if(g_prev_lpm_level == level) return;
  878. if(level==1) //25Hz
  879. {
  880. if(write_reg(misc_info->client, BT532_LPM_PERIOD_DELAY, 1000)!=I2C_SUCCESS)
  881. return;
  882. if(write_reg(misc_info->client, BT532_LPM_INTERRUPT_INTERVAL, 25)!=I2C_SUCCESS)
  883. return;
  884. if(write_reg(misc_info->client, BT532_LPM_STATE, 1)!=I2C_SUCCESS)
  885. return;
  886. }
  887. else if(level==2) //60Hz
  888. {
  889. if(write_reg(misc_info->client, BT532_LPM_PERIOD_DELAY, 150)!=I2C_SUCCESS)
  890. return;
  891. if(write_reg(misc_info->client, BT532_LPM_INTERRUPT_INTERVAL, 60)!=I2C_SUCCESS)
  892. return;
  893. if(write_reg(misc_info->client, BT532_LPM_STATE, 1)!=I2C_SUCCESS)
  894. return;
  895. }
  896. else // set default
  897. {
  898. if(write_reg(misc_info->client, BT532_LPM_PERIOD_DELAY, 1000)!=I2C_SUCCESS)
  899. return;
  900. if(write_reg(misc_info->client, BT532_LPM_INTERRUPT_INTERVAL, 25)!=I2C_SUCCESS)
  901. return;
  902. if(write_reg(misc_info->client, BT532_LPM_STATE, 3)!=I2C_SUCCESS)
  903. return;
  904. }
  905. g_prev_lpm_level = level;
  906. }
  907. static void ts_lpm_level_set(int level)
  908. {
  909. g_lpm_level = level;
  910. if(misc_info == NULL) return;
  911. if (misc_info->work_state != NOTHING)
  912. return;
  913. ts_lpm_set(g_lpm_level);
  914. }
  915. #endif
  916. static bool ts_read_coord(struct bt532_ts_info *info)
  917. {
  918. struct i2c_client *client = info->client;
  919. #if (TOUCH_POINT_MODE == 1)
  920. int i;
  921. #endif
  922. /* zinitix_debug_msg("ts_read_coord+\r\n"); */
  923. /* for Debugging Tool */
  924. if (info->touch_mode != TOUCH_POINT_MODE) {
  925. if (ts_get_raw_data(info) == false)
  926. return false;
  927. dev_err(&client->dev, "status = 0x%04X\n", info->touch_info.status);
  928. goto out;
  929. }
  930. #if (TOUCH_POINT_MODE == 1)
  931. memset(&info->touch_info,
  932. 0x0, sizeof(struct point_info));
  933. if (read_data(info->client, BT532_POINT_STATUS_REG,
  934. (u8 *)(&info->touch_info), 4) < 0) {
  935. dev_err(&client->dev, "%s: Failed to read point info\n", __func__);
  936. return false;
  937. }
  938. dev_info(&client->dev, "status reg = 0x%x , event_flag = 0x%04x\n",
  939. info->touch_info.status, info->touch_info.event_flag);
  940. if (info->touch_info.event_flag == 0)
  941. goto out;
  942. for (i = 0; i < info->cap_info.multi_fingers; i++) {
  943. if (zinitix_bit_test(info->touch_info.event_flag, i)) {
  944. udelay(20);
  945. if (read_data(info->client, BT532_POINT_STATUS_REG + 2 + ( i * 4),
  946. (u8 *)(&info->touch_info.coord[i]),
  947. sizeof(struct coord)) < 0) {
  948. dev_err(&client->dev, "Failed to read point info\n");
  949. return false;
  950. }
  951. }
  952. }
  953. #else
  954. if (read_data(info->client, BT532_POINT_STATUS_REG,
  955. (u8 *)(&info->touch_info), sizeof(struct point_info)) < 0) {
  956. dev_err(&client->dev, "Failed to read point info\n");
  957. return false;
  958. }
  959. #endif
  960. #ifdef ZINITIX_NEW_TA_COVER_REGISTER_0x11F
  961. bt532_set_optional_mode(info, false);
  962. #endif
  963. out:
  964. /* error */
  965. if (zinitix_bit_test(info->touch_info.status, BIT_MUST_ZERO)) {
  966. dev_err(&client->dev, "Invalid must zero bit(%04x)\n",
  967. info->touch_info.status);
  968. /*write_cmd(info->client, BT532_CLEAR_INT_STATUS_CMD);
  969. udelay(DELAY_FOR_SIGNAL_DELAY);*/
  970. return false;
  971. }
  972. #if defined(USE_ACTIVE_REPORT_RATE)
  973. ts_lpm_set(g_lpm_level);
  974. #endif
  975. /*
  976. if (zinitix_bit_test(info->touch_info.status, BIT_ICON_EVENT)) {
  977. udelay(20);
  978. if (read_data(info->client,
  979. BT532_ICON_STATUS_REG,
  980. (u8 *)(&info->icon_event_reg), 2) < 0) {
  981. zinitix_printk("error read icon info using i2c.\n");
  982. return false;
  983. }
  984. }
  985. */
  986. write_cmd(info->client, BT532_CLEAR_INT_STATUS_CMD);
  987. /* udelay(DELAY_FOR_SIGNAL_DELAY); */
  988. /* zinitix_debug_msg("ts_read_coord-\r\n"); */
  989. return true;
  990. }
  991. #if ESD_TIMER_INTERVAL
  992. static void esd_timeout_handler(unsigned long data)
  993. {
  994. struct bt532_ts_info *info = (struct bt532_ts_info *)data;
  995. info->p_esd_timeout_tmr = NULL;
  996. queue_work(esd_tmr_workqueue, &info->tmr_work);
  997. }
  998. static void esd_timer_start(u16 sec, struct bt532_ts_info *info)
  999. {
  1000. unsigned long flags;
  1001. spin_lock_irqsave(&info->lock, flags);
  1002. if (info->p_esd_timeout_tmr != NULL)
  1003. #ifdef CONFIG_SMP
  1004. del_singleshot_timer_sync(info->p_esd_timeout_tmr);
  1005. #else
  1006. del_timer(info->p_esd_timeout_tmr);
  1007. #endif
  1008. info->p_esd_timeout_tmr = NULL;
  1009. init_timer(&(info->esd_timeout_tmr));
  1010. info->esd_timeout_tmr.data = (unsigned long)(info);
  1011. info->esd_timeout_tmr.function = esd_timeout_handler;
  1012. info->esd_timeout_tmr.expires = jiffies + (HZ * sec);
  1013. info->p_esd_timeout_tmr = &info->esd_timeout_tmr;
  1014. add_timer(&info->esd_timeout_tmr);
  1015. spin_unlock_irqrestore(&info->lock, flags);
  1016. }
  1017. static void esd_timer_stop(struct bt532_ts_info *info)
  1018. {
  1019. unsigned long flags;
  1020. spin_lock_irqsave(&info->lock, flags);
  1021. if (info->p_esd_timeout_tmr)
  1022. #ifdef CONFIG_SMP
  1023. del_singleshot_timer_sync(info->p_esd_timeout_tmr);
  1024. #else
  1025. del_timer(info->p_esd_timeout_tmr);
  1026. #endif
  1027. info->p_esd_timeout_tmr = NULL;
  1028. spin_unlock_irqrestore(&info->lock, flags);
  1029. }
  1030. static void esd_timer_init(struct bt532_ts_info *info)
  1031. {
  1032. unsigned long flags;
  1033. spin_lock_irqsave(&info->lock, flags);
  1034. init_timer(&(info->esd_timeout_tmr));
  1035. info->esd_timeout_tmr.data = (unsigned long)(info);
  1036. info->esd_timeout_tmr.function = esd_timeout_handler;
  1037. info->p_esd_timeout_tmr = NULL;
  1038. spin_unlock_irqrestore(&info->lock, flags);
  1039. }
  1040. static void ts_tmr_work(struct work_struct *work)
  1041. {
  1042. struct bt532_ts_info *info =
  1043. container_of(work, struct bt532_ts_info, tmr_work);
  1044. struct i2c_client *client = info->client;
  1045. #if defined(TSP_VERBOSE_DEBUG)
  1046. dev_info(&client->dev, "tmr queue work ++\n");
  1047. #endif
  1048. if (down_trylock(&info->work_lock)) {
  1049. dev_err(&client->dev, "%s: Failed to occupy work lock\n", __func__);
  1050. esd_timer_start(CHECK_ESD_TIMER, info);
  1051. return;
  1052. }
  1053. if (info->work_state != NOTHING) {
  1054. dev_info(&client->dev, "%s: Other process occupied (%d)\n",
  1055. __func__, info->work_state);
  1056. up(&info->work_lock);
  1057. return;
  1058. }
  1059. info->work_state = ESD_TIMER;
  1060. disable_irq(info->irq);
  1061. bt532_power_control(info, POWER_OFF);
  1062. bt532_power_control(info, POWER_ON_SEQUENCE);
  1063. clear_report_data(info);
  1064. if (mini_init_touch(info) == false)
  1065. goto fail_time_out_init;
  1066. info->work_state = NOTHING;
  1067. enable_irq(info->irq);
  1068. up(&info->work_lock);
  1069. #if defined(TSP_VERBOSE_DEBUG)
  1070. dev_info(&client->dev, "tmr queue work--\n");
  1071. #endif
  1072. return;
  1073. fail_time_out_init:
  1074. dev_err(&client->dev, "%s: Failed to restart\n", __func__);
  1075. esd_timer_start(CHECK_ESD_TIMER, info);
  1076. info->work_state = NOTHING;
  1077. enable_irq(info->irq);
  1078. up(&info->work_lock);
  1079. return;
  1080. }
  1081. #endif
  1082. static bool bt532_power_sequence(struct bt532_ts_info *info)
  1083. {
  1084. struct i2c_client *client = info->client;
  1085. int retry = 0;
  1086. u16 chip_code;
  1087. retry_power_sequence:
  1088. if (write_reg(client, 0xc000, 0x0001) != I2C_SUCCESS) {
  1089. dev_err(&client->dev, "Failed to send power sequence(vendor cmd enable)\n");
  1090. goto fail_power_sequence;
  1091. }
  1092. udelay(10);
  1093. if (read_data(client, 0xcc00, (u8 *)&chip_code, 2) < 0) {
  1094. dev_err(&client->dev, "Failed to read chip code\n");
  1095. goto fail_power_sequence;
  1096. }
  1097. dev_info(&client->dev, "%s: chip code = 0x%x\n", __func__, chip_code);
  1098. udelay(10);
  1099. if (write_cmd(client, 0xc004) != I2C_SUCCESS) {
  1100. dev_err(&client->dev, "Failed to send power sequence(intn clear)\n");
  1101. goto fail_power_sequence;
  1102. }
  1103. udelay(10);
  1104. if (write_reg(client, 0xc002, 0x0001) != I2C_SUCCESS) {
  1105. dev_err(&client->dev, "Failed to send power sequence(nvm init)\n");
  1106. goto fail_power_sequence;
  1107. }
  1108. mdelay(2);
  1109. if (write_reg(client, 0xc001, 0x0001) != I2C_SUCCESS) {
  1110. dev_err(&client->dev, "Failed to send power sequence(program start)\n");
  1111. goto fail_power_sequence;
  1112. }
  1113. msleep(FIRMWARE_ON_DELAY); /* wait for checksum cal */
  1114. return true;
  1115. fail_power_sequence:
  1116. if (retry++ < 3) {
  1117. msleep(CHIP_ON_DELAY);
  1118. dev_info(&client->dev, "retry = %d\n", retry);
  1119. goto retry_power_sequence;
  1120. }
  1121. dev_err(&client->dev, "Failed to send power sequence\n");
  1122. return false;
  1123. }
  1124. static void bt532_hw_power(struct bt532_ts_info *info, int onoff)
  1125. {
  1126. struct bt532_ts_platform_data *pdata = info->pdata;
  1127. if(onoff){
  1128. if (info->vddo_vreg)
  1129. regulator_enable(info->vddo_vreg);
  1130. }else{
  1131. if (info->vddo_vreg)
  1132. regulator_disable(info->vddo_vreg);
  1133. }
  1134. if (pdata->tsp_supply_type == TSP_LDO_SUPPLY){
  1135. gpio_direction_output(info->pdata->tsp_en_gpio, onoff);
  1136. }else if (pdata->tsp_supply_type == TSP_REGULATOR_SUPPLY){
  1137. if(onoff){
  1138. if (info->vdd_en)
  1139. regulator_enable(info->vdd_en);
  1140. }else{
  1141. if (info->vdd_en)
  1142. regulator_disable(info->vdd_en);
  1143. }
  1144. }
  1145. return;
  1146. }
  1147. static bool bt532_power_control(struct bt532_ts_info *info, u8 ctl)
  1148. {
  1149. pr_info("[TSP] %s, %d\n", __func__, ctl);
  1150. if (ctl == POWER_OFF) {
  1151. bt532_hw_power(info, 0);
  1152. mdelay(CHIP_OFF_DELAY);
  1153. } else if (ctl == POWER_ON_SEQUENCE) {
  1154. bt532_hw_power(info, 1);
  1155. mdelay(CHIP_ON_DELAY);
  1156. msleep(CHIP_ON_DELAY);
  1157. return bt532_power_sequence(info); //zxt power on sequence
  1158. } else if (ctl == POWER_ON) {
  1159. bt532_hw_power(info, 1);
  1160. mdelay(CHIP_ON_DELAY);
  1161. }
  1162. return true;
  1163. }
  1164. static void bt532_set_ta_status(struct bt532_ts_info *info)
  1165. {
  1166. #ifndef ZINITIX_NEW_TA_COVER_REGISTER_0x11F
  1167. u16 reg_val;
  1168. #endif
  1169. printk("Inside bt532_set_ta_status()\n");
  1170. if(info->work_state == SUSPEND || info->work_state == PROBE)
  1171. return;
  1172. if (ta_connected) {
  1173. #ifdef ZINITIX_NEW_TA_COVER_REGISTER_0x11F
  1174. zinitix_bit_set(m_optional_mode, 1);
  1175. #else
  1176. read_data(info->client, 0x011e, (u8 *)&reg_val, 2);
  1177. zinitix_bit_clr(reg_val, 1);
  1178. zinitix_bit_set(reg_val, 14);
  1179. write_reg(info->client, 0x011e, reg_val);
  1180. #endif
  1181. }
  1182. else {
  1183. #ifdef ZINITIX_NEW_TA_COVER_REGISTER_0x11F
  1184. zinitix_bit_clr(m_optional_mode, 1);
  1185. #else
  1186. read_data(info->client, 0x011e, (u8 *)&reg_val, 2);
  1187. zinitix_bit_set(reg_val, 1);
  1188. zinitix_bit_clr(reg_val, 14);
  1189. write_reg(info->client, 0x011e, reg_val);
  1190. #endif
  1191. }
  1192. }
  1193. void bt532_charger_status_cb(int status)
  1194. {
  1195. int mode = (status == CABLE_TYPE_NONE);
  1196. printk("Inside bt532_charger_status_cb()\n");
  1197. if (mode)
  1198. ta_connected = false;
  1199. else
  1200. ta_connected = true;
  1201. bt532_set_ta_status(misc_info);
  1202. dev_info(&misc_info->client->dev, "TA %s\n",
  1203. mode ? "disconnected" : "connected");
  1204. }
  1205. #if TOUCH_ONESHOT_UPGRADE
  1206. static bool ts_check_need_upgrade(struct bt532_ts_info *info,
  1207. u16 cur_version, u16 cur_minor_version, u16 cur_reg_version, u16 cur_hw_id)
  1208. {
  1209. u16 new_version;
  1210. u16 new_minor_version;
  1211. u16 new_reg_version;
  1212. /* u16 new_chip_code;*/
  1213. #if CHECK_HWID
  1214. u16 new_hw_id;
  1215. #endif
  1216. new_version = (u16) (m_firmware_data[52] | (m_firmware_data[53]<<8));
  1217. new_minor_version = (u16) (m_firmware_data[56] | (m_firmware_data[57]<<8));
  1218. new_reg_version = (u16) (m_firmware_data[60] | (m_firmware_data[61]<<8));
  1219. /* new_chip_code = (u16) (m_firmware_data[64] | (m_firmware_data[65]<<8));*/
  1220. #if CHECK_HWID
  1221. new_hw_id = (u16) (m_firmware_data[0x6b12] | (m_firmware_data[0x6b13]<<8));
  1222. zinitix_printk("cur HW_ID = 0x%x, new HW_ID = 0x%x\n",
  1223. cur_hw_id, new_hw_id);
  1224. if (cur_hw_id != new_hw_id)
  1225. return true;
  1226. #endif
  1227. zinitix_printk("cur version = 0x%x, new version = 0x%x\n",
  1228. cur_version, new_version);
  1229. if(cur_version > 0xFF)
  1230. return true;
  1231. if (cur_version < new_version)
  1232. return true;
  1233. else if (cur_version > new_version)
  1234. return false;
  1235. zinitix_printk("cur minor version = 0x%x, new minor version = 0x%x\n",
  1236. cur_minor_version, new_minor_version);
  1237. if (cur_minor_version < new_minor_version)
  1238. return true;
  1239. else if (cur_minor_version > new_minor_version)
  1240. return false;
  1241. zinitix_printk("cur reg data version = 0x%x, new reg data version = 0x%x\n",
  1242. cur_reg_version, new_reg_version);
  1243. if (cur_reg_version < new_reg_version)
  1244. return true;
  1245. return false;
  1246. }
  1247. #endif
  1248. #define TC_SECTOR_SZ 8
  1249. static bool ts_upgrade_firmware(struct bt532_ts_info *info,
  1250. const u8 *firmware_data, u32 size)
  1251. {
  1252. struct i2c_client *client = info->client;
  1253. u16 flash_addr;
  1254. u8 *verify_data;
  1255. int retry_cnt = 0;
  1256. int i;
  1257. int page_sz = 64;
  1258. u16 chip_code;
  1259. verify_data = kzalloc(size, GFP_KERNEL);
  1260. if (verify_data == NULL) {
  1261. zinitix_printk(KERN_ERR "cannot alloc verify buffer\n");
  1262. return false;
  1263. }
  1264. retry_upgrade:
  1265. bt532_power_control(info, POWER_OFF);
  1266. bt532_power_control(info, POWER_ON);
  1267. mdelay(10);
  1268. if (write_reg(client, 0xc000, 0x0001) != I2C_SUCCESS) {
  1269. zinitix_printk("power sequence error (vendor cmd enable)\n");
  1270. goto fail_upgrade;
  1271. }
  1272. udelay(10);
  1273. if (read_data(client, 0xcc00, (u8 *)&chip_code, 2) < 0) {
  1274. zinitix_printk("failed to read chip code\n");
  1275. goto fail_upgrade;
  1276. }
  1277. zinitix_printk("chip code = 0x%x\n", chip_code);
  1278. page_sz = 128;
  1279. udelay(10);
  1280. if (write_cmd(client, 0xc004) != I2C_SUCCESS) {
  1281. zinitix_printk("power sequence error (intn clear)\n");
  1282. goto fail_upgrade;
  1283. }
  1284. udelay(10);
  1285. if (write_reg(client, 0xc002, 0x0001) != I2C_SUCCESS) {
  1286. zinitix_printk("power sequence error (nvm init)\n");
  1287. goto fail_upgrade;
  1288. }
  1289. mdelay(5);
  1290. zinitix_printk(KERN_INFO "init flash\n");
  1291. if (write_reg(client, 0xc003, 0x0001) != I2C_SUCCESS) {
  1292. zinitix_printk("failed to write nvm vpp on\n");
  1293. goto fail_upgrade;
  1294. }
  1295. if (write_reg(client, 0xc104, 0x0001) != I2C_SUCCESS) {
  1296. zinitix_printk("failed to write nvm wp disable\n");
  1297. goto fail_upgrade;
  1298. }
  1299. if (write_cmd(client, BT532_INIT_FLASH) != I2C_SUCCESS) {
  1300. zinitix_printk(KERN_INFO "failed to init flash\n");
  1301. goto fail_upgrade;
  1302. }
  1303. zinitix_printk(KERN_INFO "writing firmware data\n");
  1304. for (flash_addr = 0; flash_addr < size; ) {
  1305. for (i = 0; i < page_sz/TC_SECTOR_SZ; i++) {
  1306. //zinitix_debug_msg("write :addr=%04x, len=%d\n", flash_addr, TC_SECTOR_SZ);
  1307. if (write_data(client,
  1308. BT532_WRITE_FLASH,
  1309. (u8 *)&firmware_data[flash_addr], TC_SECTOR_SZ) < 0) {
  1310. zinitix_printk(KERN_INFO"error : write zinitix tc firmare\n");
  1311. goto fail_upgrade;
  1312. }
  1313. flash_addr += TC_SECTOR_SZ;
  1314. udelay(100);
  1315. }
  1316. mdelay(30); /*for fuzing delay*/
  1317. }
  1318. if (write_reg(client, 0xc003, 0x0000) != I2C_SUCCESS) {
  1319. zinitix_printk("nvm write vpp off\n");
  1320. goto fail_upgrade;
  1321. }
  1322. if (write_reg(client, 0xc104, 0x0000) != I2C_SUCCESS) {
  1323. zinitix_printk("nvm wp enable\n");
  1324. goto fail_upgrade;
  1325. }
  1326. zinitix_printk(KERN_INFO "init flash\n");
  1327. if (write_cmd(client, BT532_INIT_FLASH) != I2C_SUCCESS) {
  1328. zinitix_printk(KERN_INFO "failed to init flash\n");
  1329. goto fail_upgrade;
  1330. }
  1331. zinitix_printk(KERN_INFO "read firmware data\n");
  1332. for (flash_addr = 0; flash_addr < size; ) {
  1333. for (i = 0; i < page_sz/TC_SECTOR_SZ; i++) {
  1334. /*zinitix_debug_msg("read :addr=%04x, len=%d\n", flash_addr, TC_SECTOR_SZ);*/
  1335. if (read_firmware_data(client,
  1336. BT532_READ_FLASH,
  1337. (u8*)&verify_data[flash_addr], TC_SECTOR_SZ) < 0) {
  1338. dev_err(&client->dev, "Failed to read firmare\n");
  1339. goto fail_upgrade;
  1340. }
  1341. flash_addr += TC_SECTOR_SZ;
  1342. }
  1343. }
  1344. /* verify */
  1345. dev_info(&client->dev, "verify firmware data\n");
  1346. if (memcmp((u8 *)&firmware_data[0], (u8 *)&verify_data[0], size) == 0) {
  1347. dev_info(&client->dev, "upgrade finished\n");
  1348. kfree(verify_data);
  1349. bt532_power_control(info, POWER_OFF);
  1350. bt532_power_control(info, POWER_ON_SEQUENCE);
  1351. return true;
  1352. }
  1353. fail_upgrade:
  1354. bt532_power_control(info, POWER_OFF);
  1355. if (retry_cnt++ < INIT_RETRY_CNT) {
  1356. dev_err(&client->dev, "upgrade failed : so retry... (%d)\n", retry_cnt);
  1357. goto retry_upgrade;
  1358. }
  1359. if (verify_data != NULL)
  1360. kfree(verify_data);
  1361. dev_info(&client->dev, "Failed to upgrade\n");
  1362. return false;
  1363. }
  1364. static bool ts_hw_calibration(struct bt532_ts_info *info)
  1365. {
  1366. struct i2c_client *client = info->client;
  1367. u16 chip_eeprom_info;
  1368. int time_out = 0;
  1369. #if defined(CONFIG_SEC_DEGAS_PROJECT)
  1370. if (info->tsp_type_hw == TSP_HW_ID_INDEX_NULL){ //HW_ID 3
  1371. zinitix_printk("TSP panel wasn't connected to board\n");
  1372. return true;
  1373. }
  1374. #endif
  1375. if (write_reg(client,
  1376. BT532_TOUCH_MODE, 0x07) != I2C_SUCCESS)
  1377. return false;
  1378. mdelay(10);
  1379. write_cmd(client, BT532_CLEAR_INT_STATUS_CMD);
  1380. mdelay(10);
  1381. write_cmd(client, BT532_CLEAR_INT_STATUS_CMD);
  1382. mdelay(50);
  1383. write_cmd(client, BT532_CLEAR_INT_STATUS_CMD);
  1384. mdelay(10);
  1385. if (write_cmd(client,
  1386. BT532_CALIBRATE_CMD) != I2C_SUCCESS)
  1387. return false;
  1388. if (write_cmd(client,
  1389. BT532_CLEAR_INT_STATUS_CMD) != I2C_SUCCESS)
  1390. return false;
  1391. mdelay(10);
  1392. write_cmd(client, BT532_CLEAR_INT_STATUS_CMD);
  1393. /* wait for h/w calibration*/
  1394. do {
  1395. mdelay(500);
  1396. write_cmd(client,
  1397. BT532_CLEAR_INT_STATUS_CMD);
  1398. if (read_data(client,
  1399. BT532_EEPROM_INFO_REG,
  1400. (u8 *)&chip_eeprom_info, 2) < 0)
  1401. return false;
  1402. zinitix_debug_msg("touch eeprom info = 0x%04X\r\n",
  1403. chip_eeprom_info);
  1404. if (!zinitix_bit_test(chip_eeprom_info, 0))
  1405. break;
  1406. if (time_out++ == 4) {
  1407. write_cmd(client, BT532_CALIBRATE_CMD);
  1408. mdelay(10);
  1409. write_cmd(client, BT532_CLEAR_INT_STATUS_CMD);
  1410. dev_err(&client->dev, "h/w calibration retry timeout.\n");
  1411. }
  1412. if (time_out++ > 10) {
  1413. dev_err(&client->dev, "h/w calibration timeout.\n");
  1414. break;
  1415. }
  1416. } while (1);
  1417. if (write_reg(client,
  1418. BT532_TOUCH_MODE, TOUCH_POINT_MODE) != I2C_SUCCESS)
  1419. return false;
  1420. if (info->cap_info.ic_int_mask != 0) {
  1421. if (write_reg(client,
  1422. BT532_INT_ENABLE_FLAG,
  1423. info->cap_info.ic_int_mask)
  1424. != I2C_SUCCESS)
  1425. return false;
  1426. }
  1427. write_reg(client, 0xc003, 0x0001);
  1428. write_reg(client, 0xc104, 0x0001);
  1429. udelay(100);
  1430. if (write_cmd(client,
  1431. BT532_SAVE_CALIBRATION_CMD) != I2C_SUCCESS)
  1432. return false;
  1433. mdelay(2000);
  1434. write_reg(client, 0xc003, 0x0000);
  1435. write_reg(client, 0xc104, 0x0000);
  1436. return true;
  1437. }
  1438. static bool init_touch(struct bt532_ts_info *info)
  1439. {
  1440. struct bt532_ts_platform_data *pdata = info->pdata;
  1441. struct i2c_client *client = info->client;
  1442. struct capa_info *cap = &(info->cap_info);
  1443. u16 reg_val;
  1444. int i;
  1445. u16 chip_eeprom_info;
  1446. #if USE_CHECKSUM
  1447. u16 chip_check_sum;
  1448. u8 checksum_err;
  1449. #endif
  1450. int retry_cnt = 0;
  1451. char* productionMode = "androidboot.bsp=2";
  1452. char* checkMode = NULL;
  1453. #if defined(USE_ACTIVE_REPORT_RATE)
  1454. g_prev_lpm_level = DEF_TS_LPM_LEVEL_DEFAULT;
  1455. g_lpm_level = DEF_TS_LPM_LEVEL_DEFAULT;
  1456. #endif
  1457. checkMode = strstr(saved_command_line, productionMode);
  1458. retry_init:
  1459. for (i = 0; i < INIT_RETRY_CNT; i++) {
  1460. if (read_data(client, BT532_EEPROM_INFO_REG,
  1461. (u8 *)&chip_eeprom_info, 2) < 0) {
  1462. dev_err(&client->dev, "Failed to read eeprom info(%d)\n", i);
  1463. mdelay(10);
  1464. continue;
  1465. } else
  1466. break;
  1467. }
  1468. if (i == INIT_RETRY_CNT)
  1469. goto fail_init;
  1470. #if USE_CHECKSUM
  1471. dev_info(&client->dev, "%s: Check checksum\n", __func__);
  1472. checksum_err = 0;
  1473. for (i = 0; i < INIT_RETRY_CNT; i++) {
  1474. if (read_data(client, BT532_CHECKSUM_RESULT,
  1475. (u8 *)&chip_check_sum, 2) < 0) {
  1476. mdelay(10);
  1477. continue;
  1478. }
  1479. #if defined(TSP_VERBOSE_DEBUG)
  1480. dev_info(&client->dev, "0x%04X\n", chip_check_sum);
  1481. #endif
  1482. if(chip_check_sum == 0x55aa)
  1483. break;
  1484. else {
  1485. checksum_err = 1;
  1486. break;
  1487. }
  1488. }
  1489. if (i == INIT_RETRY_CNT || checksum_err) {
  1490. dev_err(&client->dev, "Failed to check firmware data\n");
  1491. if (checksum_err == 1 && retry_cnt < INIT_RETRY_CNT)
  1492. retry_cnt = INIT_RETRY_CNT;
  1493. goto fail_init;
  1494. }
  1495. #endif
  1496. if (write_cmd(client, BT532_SWRESET_CMD) != I2C_SUCCESS) {
  1497. dev_err(&client->dev, "Failed to write reset command\n");
  1498. goto fail_init;
  1499. }
  1500. cap->button_num = SUPPORTED_BUTTON_NUM;
  1501. reg_val = 0;
  1502. zinitix_bit_set(reg_val, BIT_PT_CNT_CHANGE);
  1503. zinitix_bit_set(reg_val, BIT_DOWN);
  1504. zinitix_bit_set(reg_val, BIT_MOVE);
  1505. zinitix_bit_set(reg_val, BIT_UP);
  1506. #if (TOUCH_POINT_MODE == 2)
  1507. zinitix_bit_set(reg_val, BIT_PALM);
  1508. zinitix_bit_set(reg_val, BIT_PALM_REJECT);
  1509. #endif
  1510. if (cap->button_num > 0)
  1511. zinitix_bit_set(reg_val, BIT_ICON_EVENT);
  1512. cap->ic_int_mask = reg_val;
  1513. if (write_reg(client, BT532_INT_ENABLE_FLAG, 0x0) != I2C_SUCCESS)
  1514. goto fail_init;
  1515. dev_info(&client->dev, "%s: Send reset command\n", __func__);
  1516. if (write_cmd(client, BT532_SWRESET_CMD) != I2C_SUCCESS)
  1517. goto fail_init;
  1518. /* get chip information */
  1519. if (read_data(client, BT532_VENDOR_ID,
  1520. (u8 *)&cap->vendor_id, 2) < 0) {
  1521. zinitix_printk("failed to read chip revision\n");
  1522. goto fail_init;
  1523. }
  1524. if (read_data(client, BT532_CHIP_REVISION,
  1525. (u8 *)&cap->ic_revision, 2) < 0) {
  1526. zinitix_printk("failed to read chip revision\n");
  1527. goto fail_init;
  1528. }
  1529. cap->ic_fw_size = 32*1024;
  1530. if (read_data(client, BT532_HW_ID, (u8 *)&cap->hw_id, 2) < 0) {
  1531. dev_err(&client->dev, "Failed to read hw id\n");
  1532. goto fail_init;
  1533. }
  1534. if (read_data(client, BT532_THRESHOLD, (u8 *)&cap->threshold, 2) < 0)
  1535. goto fail_init;
  1536. if (read_data(client, BT532_THRESHOLD,
  1537. (u8 *)&cap->threshold, 2) < 0)
  1538. goto fail_init;
  1539. if (read_data(client, BT532_BUTTON_SENSITIVITY,
  1540. (u8 *)&cap->key_threshold, 2) < 0)
  1541. goto fail_init;
  1542. if (read_data(client, BT532_DUMMY_BUTTON_SENSITIVITY,
  1543. (u8 *)&cap->dummy_threshold, 2) < 0)
  1544. goto fail_init;
  1545. if (read_data(client, BT532_TOTAL_NUMBER_OF_X,
  1546. (u8 *)&cap->x_node_num, 2) < 0)
  1547. goto fail_init;
  1548. if (read_data(client, BT532_TOTAL_NUMBER_OF_Y,
  1549. (u8 *)&cap->y_node_num, 2) < 0)
  1550. goto fail_init;
  1551. cap->total_node_num = cap->x_node_num * cap->y_node_num;
  1552. if (read_data(client, BT532_DND_N_COUNT,
  1553. (u8 *)&cap->N_cnt, 2) < 0)
  1554. goto fail_init;
  1555. zinitix_debug_msg("N count = %d\n", cap->N_cnt);
  1556. if (read_data(client, BT532_DND_U_COUNT,
  1557. (u8 *)&cap->u_cnt, 2) < 0)
  1558. goto fail_init;
  1559. zinitix_debug_msg("u count = %d\n", cap->u_cnt);
  1560. if (read_data(client, BT532_AFE_FREQUENCY,
  1561. (u8 *)&cap->afe_frequency, 2) < 0)
  1562. goto fail_init;
  1563. zinitix_debug_msg("afe frequency = %d\n", cap->afe_frequency);
  1564. if (read_data(client, BT532_DND_SHIFT_VALUE,
  1565. (u8 *)&cap->shift_value, 2) < 0)
  1566. goto fail_init;
  1567. /* get chip firmware version */
  1568. if (read_data(client, BT532_FIRMWARE_VERSION,
  1569. (u8 *)&cap->fw_version, 2) < 0)
  1570. goto fail_init;
  1571. if (read_data(client, BT532_MINOR_FW_VERSION,
  1572. (u8 *)&cap->fw_minor_version, 2) < 0)
  1573. goto fail_init;
  1574. if (read_data(client, BT532_DATA_VERSION_REG,
  1575. (u8 *)&cap->reg_data_version, 2) < 0)
  1576. goto fail_init;
  1577. #if TOUCH_ONESHOT_UPGRADE
  1578. if ((checkMode == NULL) &&(ts_check_need_upgrade(info, cap->fw_version,
  1579. cap->fw_minor_version, cap->reg_data_version,
  1580. cap->hw_id) == true)) {
  1581. zinitix_printk("start upgrade firmware\n");
  1582. if (ts_upgrade_firmware(info, m_firmware_data,
  1583. cap->ic_fw_size) == false)
  1584. goto fail_init;
  1585. if (ts_hw_calibration(info) == false)
  1586. goto fail_init;
  1587. /* disable chip interrupt */
  1588. if (write_reg(client, BT532_INT_ENABLE_FLAG, 0) != I2C_SUCCESS)
  1589. goto fail_init;
  1590. /* get chip firmware version */
  1591. if (read_data(client, BT532_FIRMWARE_VERSION,
  1592. (u8 *)&cap->fw_version, 2) < 0)
  1593. goto fail_init;
  1594. if (read_data(client, BT532_MINOR_FW_VERSION,
  1595. (u8 *)&cap->fw_minor_version, 2) < 0)
  1596. goto fail_init;
  1597. if (read_data(client, BT532_DATA_VERSION_REG,
  1598. (u8 *)&cap->reg_data_version, 2) < 0)
  1599. goto fail_init;
  1600. }
  1601. #endif
  1602. if (read_data(client, BT532_EEPROM_INFO_REG,
  1603. (u8 *)&chip_eeprom_info, 2) < 0)
  1604. goto fail_init;
  1605. if (zinitix_bit_test(chip_eeprom_info, 0)) { /* hw calibration bit*/
  1606. if (ts_hw_calibration(info) == false)
  1607. goto fail_init;
  1608. /* disable chip interrupt */
  1609. if (write_reg(client, BT532_INT_ENABLE_FLAG, 0) != I2C_SUCCESS)
  1610. goto fail_init;
  1611. }
  1612. /* initialize */
  1613. if (write_reg(client, BT532_X_RESOLUTION,
  1614. (u16)pdata->x_resolution) != I2C_SUCCESS)
  1615. goto fail_init;
  1616. if (write_reg(client, BT532_Y_RESOLUTION,
  1617. (u16)pdata->y_resolution) != I2C_SUCCESS)
  1618. goto fail_init;
  1619. cap->MinX = (u32)0;
  1620. cap->MinY = (u32)0;
  1621. cap->MaxX = (u32)pdata->x_resolution;
  1622. cap->MaxY = (u32)pdata->y_resolution;
  1623. if (write_reg(client, BT532_BUTTON_SUPPORTED_NUM,
  1624. (u16)cap->button_num) != I2C_SUCCESS)
  1625. goto fail_init;
  1626. if (write_reg(client, BT532_SUPPORTED_FINGER_NUM,
  1627. (u16)MAX_SUPPORTED_FINGER_NUM) != I2C_SUCCESS)
  1628. goto fail_init;
  1629. cap->multi_fingers = MAX_SUPPORTED_FINGER_NUM;
  1630. zinitix_debug_msg("max supported finger num = %d\r\n",
  1631. cap->multi_fingers);
  1632. cap->gesture_support = 0;
  1633. zinitix_debug_msg("set other configuration\r\n");
  1634. if (write_reg(client, BT532_INITIAL_TOUCH_MODE,
  1635. TOUCH_POINT_MODE) != I2C_SUCCESS)
  1636. goto fail_init;
  1637. if (write_reg(client, BT532_TOUCH_MODE, info->touch_mode) != I2C_SUCCESS)
  1638. goto fail_init;
  1639. #ifdef ZINITIX_NEW_TA_COVER_REGISTER_0x11F
  1640. read_data(client, ZINITIX_INTERNAL_FLAG_03, (u8 *)&g_internal_flag_03, 2);
  1641. zinitix_bit_clr(g_internal_flag_03, 1); //TA
  1642. zinitix_bit_clr(g_internal_flag_03, 2); //cover
  1643. bt532_set_optional_mode(info, true);
  1644. #else
  1645. bt532_set_ta_status(info);
  1646. #endif
  1647. /* soft calibration */
  1648. // if (write_cmd(client, BT532_CALIBRATE_CMD) != I2C_SUCCESS)
  1649. // goto fail_init;
  1650. if (write_reg(client, BT532_INT_ENABLE_FLAG,
  1651. cap->ic_int_mask) != I2C_SUCCESS)
  1652. goto fail_init;
  1653. /* read garbage data */
  1654. for (i = 0; i < 10; i++) {
  1655. write_cmd(client, BT532_CLEAR_INT_STATUS_CMD);
  1656. udelay(10);
  1657. }
  1658. if (info->touch_mode != TOUCH_POINT_MODE) { /* Test Mode */
  1659. if (write_reg(client, BT532_DELAY_RAW_FOR_HOST,
  1660. RAWDATA_DELAY_FOR_HOST) != I2C_SUCCESS) {
  1661. dev_err(&client->dev, "%s: Failed to set DELAY_RAW_FOR_HOST\n",
  1662. __func__);
  1663. goto fail_init;
  1664. }
  1665. }
  1666. #if ESD_TIMER_INTERVAL
  1667. if (write_reg(client, BT532_PERIODICAL_INTERRUPT_INTERVAL,
  1668. SCAN_RATE_HZ * ESD_TIMER_INTERVAL) != I2C_SUCCESS)
  1669. goto fail_init;
  1670. read_data(client, BT532_PERIODICAL_INTERRUPT_INTERVAL, (u8 *)&reg_val, 2);
  1671. #if defined(TSP_VERBOSE_DEBUG)
  1672. dev_info(&client->dev, "Esd timer register = %d\n", reg_val);
  1673. #endif
  1674. #endif
  1675. zinitix_debug_msg("successfully initialized\r\n");
  1676. return true;
  1677. fail_init:
  1678. if (++retry_cnt <= INIT_RETRY_CNT) {
  1679. bt532_power_control(info, POWER_OFF);
  1680. bt532_power_control(info, POWER_ON_SEQUENCE);
  1681. zinitix_debug_msg("retry to initiallize(retry cnt = %d)\r\n",
  1682. retry_cnt);
  1683. goto retry_init;
  1684. } else if (retry_cnt == INIT_RETRY_CNT+1) {
  1685. cap->ic_fw_size = 32*1024;
  1686. zinitix_debug_msg("retry to initiallize(retry cnt = %d)\r\n", retry_cnt);
  1687. #if TOUCH_FORCE_UPGRADE
  1688. if(checkMode == NULL) {
  1689. if (ts_upgrade_firmware(info, m_firmware_data,
  1690. cap->ic_fw_size) == false) {
  1691. zinitix_printk("upgrade failed\n");
  1692. return false;
  1693. }
  1694. }
  1695. else
  1696. return true;
  1697. mdelay(100);
  1698. /* hw calibration and make checksum */
  1699. if (ts_hw_calibration(info) == false) {
  1700. zinitix_printk("failed to initiallize\r\n");
  1701. return false;
  1702. }
  1703. goto retry_init;
  1704. #endif
  1705. }
  1706. dev_err(&client->dev, "Failed to initiallize\n");
  1707. return false;
  1708. }
  1709. static bool mini_init_touch(struct bt532_ts_info *info)
  1710. {
  1711. struct bt532_ts_platform_data *pdata = info->pdata;
  1712. struct i2c_client *client = info->client;
  1713. int i;
  1714. #if USE_CHECKSUM
  1715. u16 chip_check_sum;
  1716. dev_info(&client->dev, "check checksum\n");
  1717. if (read_data(client, BT532_CHECKSUM_RESULT,
  1718. (u8 *)&chip_check_sum, 2) < 0)
  1719. goto fail_mini_init;
  1720. if (chip_check_sum != 0x55aa) {
  1721. dev_err(&client->dev, "Failed to check firmware"
  1722. " checksum(0x%04x)\n", chip_check_sum);
  1723. goto fail_mini_init;
  1724. }
  1725. #endif
  1726. #if defined(USE_ACTIVE_REPORT_RATE)
  1727. g_prev_lpm_level = DEF_TS_LPM_LEVEL_DEFAULT;
  1728. g_lpm_level = DEF_TS_LPM_LEVEL_DEFAULT;
  1729. #endif
  1730. if (write_cmd(client, BT532_SWRESET_CMD) != I2C_SUCCESS) {
  1731. dev_info(&client->dev, "Failed to write reset command\n");
  1732. goto fail_mini_init;
  1733. }
  1734. /* initialize */
  1735. if (write_reg(client, BT532_X_RESOLUTION,
  1736. (u16)(pdata->x_resolution)) != I2C_SUCCESS)
  1737. goto fail_mini_init;
  1738. if (write_reg(client, BT532_Y_RESOLUTION,
  1739. (u16)(pdata->y_resolution)) != I2C_SUCCESS)
  1740. goto fail_mini_init;
  1741. dev_info(&client->dev, "touch max x = %d\r\n", pdata->x_resolution);
  1742. dev_info(&client->dev, "touch max y = %d\r\n", pdata->y_resolution);
  1743. if (write_reg(client, BT532_BUTTON_SUPPORTED_NUM,
  1744. (u16)info->cap_info.button_num) != I2C_SUCCESS)
  1745. goto fail_mini_init;
  1746. if (write_reg(client, BT532_SUPPORTED_FINGER_NUM,
  1747. (u16)MAX_SUPPORTED_FINGER_NUM) != I2C_SUCCESS)
  1748. goto fail_mini_init;
  1749. if (write_reg(client, BT532_INITIAL_TOUCH_MODE,
  1750. TOUCH_POINT_MODE) != I2C_SUCCESS)
  1751. goto fail_mini_init;
  1752. if (write_reg(client, BT532_TOUCH_MODE,
  1753. info->touch_mode) != I2C_SUCCESS)
  1754. goto fail_mini_init;
  1755. #ifdef ZINITIX_NEW_TA_COVER_REGISTER_0x11F
  1756. bt532_set_optional_mode(info, true);
  1757. #else
  1758. bt532_set_ta_status(info);
  1759. /* soft calibration */
  1760. if (write_cmd(client, BT532_CALIBRATE_CMD) != I2C_SUCCESS)
  1761. goto fail_mini_init;
  1762. #endif
  1763. if (write_reg(client, BT532_INT_ENABLE_FLAG,
  1764. info->cap_info.ic_int_mask) != I2C_SUCCESS)
  1765. goto fail_mini_init;
  1766. /* read garbage data */
  1767. for (i = 0; i < 10; i++) {
  1768. write_cmd(client, BT532_CLEAR_INT_STATUS_CMD);
  1769. udelay(10);
  1770. }
  1771. if (info->touch_mode != TOUCH_POINT_MODE) {
  1772. if (write_reg(client, BT532_DELAY_RAW_FOR_HOST,
  1773. RAWDATA_DELAY_FOR_HOST) != I2C_SUCCESS){
  1774. dev_err(&client->dev, "Failed to set BT532_DELAY_RAW_FOR_HOST\n");
  1775. goto fail_mini_init;
  1776. }
  1777. }
  1778. #if ESD_TIMER_INTERVAL
  1779. if (write_reg(client, BT532_PERIODICAL_INTERRUPT_INTERVAL,
  1780. SCAN_RATE_HZ * ESD_TIMER_INTERVAL) != I2C_SUCCESS)
  1781. goto fail_mini_init;
  1782. esd_timer_start(CHECK_ESD_TIMER, info);
  1783. #if defined(TSP_VERBOSE_DEBUG)
  1784. dev_info(&client->dev, "Started esd timer\n");
  1785. #endif
  1786. #endif
  1787. dev_info(&client->dev, "Successfully mini initialized\r\n");
  1788. return true;
  1789. fail_mini_init:
  1790. dev_err(&client->dev, "Failed to initialize mini init\n");
  1791. bt532_power_control(info, POWER_OFF);
  1792. bt532_power_control(info, POWER_ON_SEQUENCE);
  1793. if (init_touch(info) == false) {
  1794. dev_err(&client->dev, "Failed to initialize\n");
  1795. return false;
  1796. }
  1797. #if ESD_TIMER_INTERVAL
  1798. esd_timer_start(CHECK_ESD_TIMER, info);
  1799. #if defined(TSP_VERBOSE_DEBUG)
  1800. dev_info(&client->dev, "Started esd timer\n");
  1801. #endif
  1802. #endif
  1803. return true;
  1804. }
  1805. #ifdef TSP_BOOSTER
  1806. static void change_dvfs_lock(struct work_struct *work)
  1807. {
  1808. struct bt532_ts_info *info = container_of(work,
  1809. struct bt532_ts_info, work_dvfs_chg.work);
  1810. int ret = 0;
  1811. mutex_lock(&info->dvfs_lock);
  1812. if (info->boost_level == DVFS_STAGE_DUAL) {
  1813. ret = set_freq_limit(DVFS_TOUCH_ID, MIN_TOUCH_LIMIT_SECOND);
  1814. info->dvfs_freq = MIN_TOUCH_LIMIT_SECOND;
  1815. } else if (info->boost_level == DVFS_STAGE_SINGLE) {
  1816. ret = set_freq_limit(DVFS_TOUCH_ID, -1);
  1817. info->dvfs_freq = -1;
  1818. }
  1819. if (ret < 0)
  1820. printk(KERN_ERR "bt532_ts_device TSP %s: booster stop failed(%d)\n",\
  1821. __func__, __LINE__);
  1822. mutex_unlock(&info->dvfs_lock);
  1823. }
  1824. static void set_dvfs_off(struct work_struct *work)
  1825. {
  1826. struct bt532_ts_info *info = container_of(work,
  1827. struct bt532_ts_info, work_dvfs_off.work);
  1828. int ret;
  1829. mutex_lock(&info->dvfs_lock);
  1830. ret = set_freq_limit(DVFS_TOUCH_ID, -1);
  1831. if (ret < 0)
  1832. printk(KERN_ERR "bt532_ts_device TSP %s: booster stop failed(%d)\n",\
  1833. __func__, __LINE__);
  1834. info->dvfs_freq = -1;
  1835. info->dvfs_lock_status = false;
  1836. mutex_unlock(&info->dvfs_lock);
  1837. }
  1838. static void set_dvfs_lock(struct bt532_ts_info *info, uint32_t on, bool mode)
  1839. {
  1840. int ret = 0;
  1841. if (DVFS_STAGE_NONE == info->boost_level)
  1842. return;
  1843. mutex_lock(&info->dvfs_lock);
  1844. if (on == 0) {
  1845. if (info->dvfs_lock_status) {
  1846. schedule_delayed_work(&info->work_dvfs_off,
  1847. msecs_to_jiffies(TOUCH_BOOSTER_OFF_TIME));
  1848. }
  1849. } else if (on == 1) {
  1850. cancel_delayed_work(&info->work_dvfs_off);
  1851. if (!info->dvfs_lock_status || mode) {
  1852. if (info->dvfs_old_status != on) {
  1853. cancel_delayed_work(&info->work_dvfs_chg);
  1854. if (info->dvfs_freq != MIN_TOUCH_LIMIT) {
  1855. ret = set_freq_limit(DVFS_TOUCH_ID,
  1856. MIN_TOUCH_LIMIT);
  1857. info->dvfs_freq = MIN_TOUCH_LIMIT;
  1858. if (ret < 0)
  1859. printk(KERN_ERR
  1860. "%s: cpu first lock failed(%d)\n",
  1861. __func__, ret);
  1862. schedule_delayed_work(&info->work_dvfs_chg,
  1863. msecs_to_jiffies(TOUCH_BOOSTER_CHG_TIME));
  1864. info->dvfs_lock_status = true;
  1865. }
  1866. }
  1867. }
  1868. } else if (on == 2) {
  1869. if (info->dvfs_lock_status) {
  1870. cancel_delayed_work(&info->work_dvfs_off);
  1871. cancel_delayed_work(&info->work_dvfs_chg);
  1872. schedule_work(&info->work_dvfs_off.work);
  1873. }
  1874. }
  1875. info->dvfs_old_status = on;
  1876. mutex_unlock(&info->dvfs_lock);
  1877. }
  1878. #endif
  1879. static void clear_report_data(struct bt532_ts_info *info)
  1880. {
  1881. int i;
  1882. u8 reported = 0;
  1883. u8 sub_status;
  1884. for (i = 0; i < info->cap_info.button_num; i++) {
  1885. if (info->button[i] == ICON_BUTTON_DOWN) {
  1886. info->button[i] = ICON_BUTTON_UP;
  1887. input_report_key(info->input_dev, BUTTON_MAPPING_KEY[i], 0);
  1888. reported = true;
  1889. #if !defined(CONFIG_SAMSUNG_PRODUCT_SHIP)
  1890. printk(KERN_INFO "Button up = %d\n", i);
  1891. #else
  1892. printk(KERN_INFO "Button up\n");
  1893. #endif
  1894. }
  1895. }
  1896. for (i = 0; i < info->cap_info.multi_fingers; i++) {
  1897. sub_status = info->reported_touch_info.coord[i].sub_status;
  1898. if (zinitix_bit_test(sub_status, SUB_BIT_EXIST)) {
  1899. input_mt_slot(info->input_dev, i);
  1900. input_mt_report_slot_state(info->input_dev, MT_TOOL_FINGER, 0);
  1901. reported = true;
  1902. if (!m_ts_debug_mode && TSP_NORMAL_EVENT_MSG)
  1903. printk(KERN_INFO "[TSP] R %02d\r\n", i);
  1904. }
  1905. info->reported_touch_info.coord[i].sub_status = 0;
  1906. }
  1907. if (reported)
  1908. input_sync(info->input_dev);
  1909. #ifdef TSP_BOOSTER
  1910. if (info->touch_pressed_num != 0) {
  1911. printk("bt532_ts_device : %s force dvfs off\n", __func__);
  1912. info->touch_pressed_num = 0;
  1913. set_dvfs_lock(info, 2, false);
  1914. }
  1915. #endif
  1916. }
  1917. #define PALM_REPORT_WIDTH 200
  1918. #define PALM_REJECT_WIDTH 255
  1919. static irqreturn_t bt532_touch_work(int irq, void *data)
  1920. {
  1921. struct bt532_ts_info *info = (struct bt532_ts_info *)data;
  1922. struct bt532_ts_platform_data *pdata = info->pdata;
  1923. struct i2c_client *client = info->client;
  1924. int i;
  1925. u8 reported = false;
  1926. u8 sub_status;
  1927. u8 prev_sub_status;
  1928. u32 x, y, maxX, maxY;
  1929. u32 w;
  1930. u32 tmp;
  1931. u8 palm = 0;
  1932. #ifdef TSP_BOOSTER
  1933. bool touch_press = false;
  1934. #endif
  1935. if (gpio_get_value(info->pdata->gpio_int)) {
  1936. dev_err(&client->dev, "Invalid interrupt\n");
  1937. return IRQ_HANDLED;
  1938. }
  1939. if (down_trylock(&info->work_lock)) {
  1940. dev_err(&client->dev, "%s: Failed to occupy work lock\n", __func__);
  1941. write_cmd(client, BT532_CLEAR_INT_STATUS_CMD);
  1942. return IRQ_HANDLED;
  1943. }
  1944. #if ESD_TIMER_INTERVAL
  1945. esd_timer_stop(info);
  1946. #endif
  1947. if (info->work_state != NOTHING) {
  1948. dev_err(&client->dev, "%s: Other process occupied\n", __func__);
  1949. udelay(DELAY_FOR_SIGNAL_DELAY);
  1950. if (!gpio_get_value(info->pdata->gpio_int)) {
  1951. write_cmd(client, BT532_CLEAR_INT_STATUS_CMD);
  1952. udelay(DELAY_FOR_SIGNAL_DELAY);
  1953. }
  1954. goto out;
  1955. }
  1956. info->work_state = NORMAL;
  1957. if (ts_read_coord(info) == false || info->touch_info.status == 0xffff
  1958. || info->touch_info.status == 0x1) { /* maybe desirable reset */
  1959. dev_err(&client->dev, "Failed to read info coord\n");
  1960. bt532_power_control(info, POWER_OFF);
  1961. bt532_power_control(info, POWER_ON_SEQUENCE);
  1962. clear_report_data(info);
  1963. mini_init_touch(info);
  1964. goto out;
  1965. }
  1966. /* invalid : maybe periodical repeated int. */
  1967. if (info->touch_info.status == 0x0)
  1968. goto out;
  1969. reported = false;
  1970. if (zinitix_bit_test(info->touch_info.status, BIT_ICON_EVENT)) {
  1971. if (read_data(info->client, BT532_ICON_STATUS_REG,
  1972. (u8 *)(&info->icon_event_reg), 2) < 0) {
  1973. dev_err(&client->dev, "Failed to read button info\n");
  1974. write_cmd(client, BT532_CLEAR_INT_STATUS_CMD);
  1975. goto out;
  1976. }
  1977. for (i = 0; i < info->cap_info.button_num; i++) {
  1978. if (zinitix_bit_test(info->icon_event_reg,
  1979. (BIT_O_ICON0_DOWN + i))) {
  1980. info->button[i] = ICON_BUTTON_DOWN;
  1981. input_report_key(info->input_dev, BUTTON_MAPPING_KEY[i], 1);
  1982. reported = true;
  1983. #if !defined(CONFIG_SAMSUNG_PRODUCT_SHIP)
  1984. dev_info(&client->dev, "Button down = %d\n", i);
  1985. #else
  1986. dev_info(&client->dev, "Button down\n");
  1987. #endif
  1988. }
  1989. }
  1990. for (i = 0; i < info->cap_info.button_num; i++) {
  1991. if (zinitix_bit_test(info->icon_event_reg,
  1992. (BIT_O_ICON0_UP + i))) {
  1993. info->button[i] = ICON_BUTTON_UP;
  1994. input_report_key(info->input_dev, BUTTON_MAPPING_KEY[i], 0);
  1995. reported = true;
  1996. #if !defined(CONFIG_SAMSUNG_PRODUCT_SHIP)
  1997. dev_info(&client->dev, "Button up = %d\n", i);
  1998. #else
  1999. dev_info(&client->dev, "Button up\n");
  2000. #endif
  2001. }
  2002. }
  2003. }
  2004. /* if button press or up event occured... */
  2005. if (reported == true ||
  2006. !zinitix_bit_test(info->touch_info.status, BIT_PT_EXIST)) {
  2007. for (i = 0; i < info->cap_info.multi_fingers; i++) {
  2008. prev_sub_status = info->reported_touch_info.coord[i].sub_status;
  2009. if (zinitix_bit_test(prev_sub_status, SUB_BIT_EXIST)) {
  2010. #if !defined(CONFIG_SAMSUNG_PRODUCT_SHIP)
  2011. dev_info(&client->dev, "Finger [%02d] up\n", i);
  2012. #else
  2013. dev_info(&client->dev, "Finger up\n");
  2014. #endif
  2015. input_mt_slot(info->input_dev, i);
  2016. input_mt_report_slot_state(info->input_dev,
  2017. MT_TOOL_FINGER, 0);
  2018. #ifdef TSP_BOOSTER
  2019. info->touch_pressed_num--;
  2020. #endif
  2021. }
  2022. }
  2023. memset(&info->reported_touch_info, 0x0, sizeof(struct point_info));
  2024. input_sync(info->input_dev);
  2025. if (reported == true) /* for button event */
  2026. udelay(100);
  2027. #ifdef TSP_BOOSTER
  2028. goto touch_booster_out;
  2029. #else
  2030. goto out;
  2031. #endif
  2032. }
  2033. #ifdef SUPPORTED_PALM_TOUCH
  2034. if (zinitix_bit_test(info->touch_info.status, BIT_PALM)) {
  2035. #if !defined(CONFIG_SAMSUNG_PRODUCT_SHIP)
  2036. dev_info(&client->dev, "Palm report\n");
  2037. #endif
  2038. palm = 1;
  2039. }
  2040. if (zinitix_bit_test(info->touch_info.status, BIT_PALM_REJECT)) {
  2041. #if !defined(CONFIG_SAMSUNG_PRODUCT_SHIP)
  2042. dev_info(&client->dev, "Palm reject\n");
  2043. #endif
  2044. palm = 2;
  2045. }
  2046. #endif
  2047. for (i = 0; i < info->cap_info.multi_fingers; i++) {
  2048. sub_status = info->touch_info.coord[i].sub_status;
  2049. prev_sub_status = info->reported_touch_info.coord[i].sub_status;
  2050. if (zinitix_bit_test(sub_status, SUB_BIT_EXIST)) {
  2051. x = info->touch_info.coord[i].x;
  2052. y = info->touch_info.coord[i].y;
  2053. w = info->touch_info.coord[i].width;
  2054. /* transformation from touch to screen orientation */
  2055. if (pdata->orientation & TOUCH_V_FLIP)
  2056. y = info->cap_info.MaxY
  2057. + info->cap_info.MinY - y;
  2058. if (pdata->orientation & TOUCH_H_FLIP)
  2059. x = info->cap_info.MaxX
  2060. + info->cap_info.MinX - x;
  2061. maxX = info->cap_info.MaxX;
  2062. maxY = info->cap_info.MaxY;
  2063. if (pdata->orientation & TOUCH_XY_SWAP) {
  2064. zinitix_swap_v(x, y, tmp);
  2065. zinitix_swap_v(maxX, maxY, tmp);
  2066. }
  2067. if (x > maxX || y > maxY) {
  2068. #if !defined(CONFIG_SAMSUNG_PRODUCT_SHIP)
  2069. dev_err(&client->dev,
  2070. "Invalid coord %d : x=%d, y=%d\n", i, x, y);
  2071. #endif
  2072. continue;
  2073. }
  2074. info->touch_info.coord[i].x = x;
  2075. info->touch_info.coord[i].y = y;
  2076. if (zinitix_bit_test(sub_status, SUB_BIT_DOWN)) {
  2077. #if !defined(CONFIG_SAMSUNG_PRODUCT_SHIP)
  2078. dev_info(&client->dev, "Finger [%02d] x = %d, y = %d,"
  2079. " w = %d\n", i, x, y, w);
  2080. #else
  2081. dev_info(&client->dev, "Finger down\n");
  2082. #endif
  2083. #ifdef TSP_BOOSTER
  2084. info->touch_pressed_num++;
  2085. touch_press = true;
  2086. #endif
  2087. }
  2088. if (w == 0)
  2089. w = 1;
  2090. input_mt_slot(info->input_dev, i);
  2091. input_mt_report_slot_state(info->input_dev, MT_TOOL_FINGER, 1);
  2092. #if (TOUCH_POINT_MODE == 2)
  2093. if (palm == 0) {
  2094. if (w >= PALM_REPORT_WIDTH)
  2095. w = PALM_REPORT_WIDTH - 10;
  2096. } else if (palm == 1) { //palm report
  2097. w = PALM_REPORT_WIDTH;
  2098. // info->touch_info.coord[i].minor_width = PALM_REPORT_WIDTH;
  2099. } else if (palm == 2){ // palm reject
  2100. // x = y = 0;
  2101. w = PALM_REJECT_WIDTH;
  2102. // info->touch_info.coord[i].minor_width = PALM_REJECT_WIDTH;
  2103. }
  2104. #endif
  2105. input_report_abs(info->input_dev, ABS_MT_TOUCH_MAJOR, (u32)w);
  2106. input_report_abs(info->input_dev, ABS_MT_PRESSURE, (u32)w);
  2107. input_report_abs(info->input_dev, ABS_MT_WIDTH_MAJOR,
  2108. (u32)((palm == 1) ? w-40 : w));
  2109. #if (TOUCH_POINT_MODE == 2)
  2110. input_report_abs(info->input_dev,
  2111. ABS_MT_TOUCH_MINOR, (u32)info->touch_info.coord[i].minor_width);
  2112. // input_report_abs(info->input_dev,
  2113. // ABS_MT_WIDTH_MINOR, (u32)info->touch_info.coord[i].minor_width);
  2114. #ifdef SUPPORTED_PALM_TOUCH
  2115. input_report_abs(info->input_dev, ABS_MT_PALM, (palm > 0)?1:0);
  2116. #endif
  2117. // input_report_abs(info->input_dev, ABS_MT_PALM, 1);
  2118. #endif
  2119. input_report_abs(info->input_dev, ABS_MT_POSITION_X, x);
  2120. input_report_abs(info->input_dev, ABS_MT_POSITION_Y, y);
  2121. } else if (zinitix_bit_test(sub_status, SUB_BIT_UP) ||
  2122. zinitix_bit_test(prev_sub_status, SUB_BIT_EXIST)) {
  2123. #if !defined(CONFIG_SAMSUNG_PRODUCT_SHIP)
  2124. dev_info(&client->dev, "Finger [%02d] up\n", i);
  2125. #else
  2126. dev_info(&client->dev, "Finger up\n");
  2127. #endif
  2128. memset(&info->touch_info.coord[i], 0x0, sizeof(struct coord));
  2129. input_mt_slot(info->input_dev, i);
  2130. input_mt_report_slot_state(info->input_dev, MT_TOOL_FINGER, 0);
  2131. #ifdef TSP_BOOSTER
  2132. info->touch_pressed_num--;
  2133. #endif
  2134. } else {
  2135. memset(&info->touch_info.coord[i], 0x0, sizeof(struct coord));
  2136. }
  2137. }
  2138. memcpy((char *)&info->reported_touch_info, (char *)&info->touch_info,
  2139. sizeof(struct point_info));
  2140. input_sync(info->input_dev);
  2141. #ifdef TSP_BOOSTER
  2142. touch_booster_out:
  2143. if (!!info->touch_pressed_num){
  2144. if(touch_press)
  2145. set_dvfs_lock(info, 1, true);
  2146. }
  2147. else{
  2148. set_dvfs_lock(info, 0, false);
  2149. }
  2150. #endif
  2151. out:
  2152. if (info->work_state == NORMAL) {
  2153. #if ESD_TIMER_INTERVAL
  2154. esd_timer_start(CHECK_ESD_TIMER, info);
  2155. #endif
  2156. info->work_state = NOTHING;
  2157. }
  2158. up(&info->work_lock);
  2159. return IRQ_HANDLED;
  2160. }
  2161. #if defined(CONFIG_PM)
  2162. static int bt532_ts_resume(struct device *dev)
  2163. {
  2164. struct i2c_client *client = to_i2c_client(dev);
  2165. struct bt532_ts_info *info = i2c_get_clientdata(client);
  2166. if(info->device_enabled)
  2167. return 0;
  2168. info->device_enabled = 1;
  2169. #if defined(TSP_VERBOSE_DEBUG)
  2170. dev_info(&client->dev, "resume++\n");
  2171. #endif
  2172. down(&info->work_lock);
  2173. if (info->work_state != SUSPEND) {
  2174. dev_err(&client->dev, "%s: Invalid work proceedure (%d)\n",
  2175. __func__, info->work_state);
  2176. up(&info->work_lock);
  2177. return 0;
  2178. }
  2179. bt532_power_control(info, POWER_ON_SEQUENCE);
  2180. info->work_state = NOTHING;
  2181. if (mini_init_touch(info) == false)
  2182. dev_err(&client->dev, "Failed to resume\n");
  2183. enable_irq(info->irq);
  2184. #if defined(TSP_VERBOSE_DEBUG)
  2185. dev_info(&client->dev, "resume--\n");
  2186. #endif
  2187. up(&info->work_lock);
  2188. return 0;
  2189. }
  2190. static int bt532_ts_suspend(struct device *dev)
  2191. {
  2192. struct i2c_client *client = to_i2c_client(dev);
  2193. struct bt532_ts_info *info = i2c_get_clientdata(client);
  2194. if(!info->device_enabled)
  2195. return 0;
  2196. info->device_enabled = 0;
  2197. #if defined(TSP_VERBOSE_DEBUG)
  2198. dev_info(&client->dev, "suspend++\n");
  2199. #endif
  2200. disable_irq(info->irq);
  2201. #if ESD_TIMER_INTERVAL
  2202. flush_work(&info->tmr_work);
  2203. #endif
  2204. down(&info->work_lock);
  2205. if (info->work_state != NOTHING
  2206. && info->work_state != SUSPEND) {
  2207. dev_err(&client->dev, "%s: Invalid work proceedure (%d)\n",
  2208. __func__, info->work_state);
  2209. up(&info->work_lock);
  2210. enable_irq(info->irq);
  2211. return 0;
  2212. }
  2213. clear_report_data(info);
  2214. #if ESD_TIMER_INTERVAL
  2215. esd_timer_stop(info);
  2216. #if defined(TSP_VERBOSE_DEBUG)
  2217. dev_info(&client->dev, "Stopped esd timer\n");
  2218. #endif
  2219. #endif
  2220. write_cmd(info->client, BT532_SLEEP_CMD);
  2221. bt532_power_control(info, POWER_OFF);
  2222. info->work_state = SUSPEND;
  2223. #if defined(TSP_VERBOSE_DEBUG)
  2224. zinitix_printk("suspend--\n");
  2225. #endif
  2226. up(&info->work_lock);
  2227. return 0;
  2228. }
  2229. #endif
  2230. static int bt532_input_open(struct input_dev *dev)
  2231. {
  2232. struct bt532_ts_info *info;
  2233. pr_info("[TSP] %s\n", __func__);
  2234. info = input_get_drvdata(dev);
  2235. return bt532_ts_resume(&info->client->dev);
  2236. }
  2237. static void bt532_input_close(struct input_dev *dev)
  2238. {
  2239. struct bt532_ts_info *info;
  2240. pr_info("[TSP] %s\n", __func__);
  2241. info = input_get_drvdata(dev);
  2242. bt532_ts_suspend(&info->client->dev);
  2243. }
  2244. static bool ts_set_touchmode(u16 value)
  2245. {
  2246. int i;
  2247. #ifndef ZINITIX_NEW_TA_COVER_REGISTER_0x11F
  2248. u16 reg_val;
  2249. #endif
  2250. disable_irq(misc_info->irq);
  2251. down(&misc_info->work_lock);
  2252. if (misc_info->work_state != NOTHING) {
  2253. printk(KERN_INFO "other process occupied.. (%d)\n",
  2254. misc_info->work_state);
  2255. enable_irq(misc_info->irq);
  2256. up(&misc_info->work_lock);
  2257. return -1;
  2258. }
  2259. misc_info->work_state = SET_MODE;
  2260. if (value == TOUCH_DND_MODE) {
  2261. #ifndef ZINITIX_NEW_TA_COVER_REGISTER_0x11F
  2262. read_data(misc_info->client, 0x011e, (u8 *)&reg_val, 2);
  2263. zinitix_bit_clr(reg_val, 1);
  2264. write_reg(misc_info->client, 0x011e, reg_val);
  2265. #endif
  2266. if (write_reg(misc_info->client, BT532_DND_SHIFT_VALUE,
  2267. SEC_DND_SHIFT_VALUE) != I2C_SUCCESS)
  2268. dev_err(&misc_info->client->dev, "Failed to set DND_SHIFT_VALUE\n");
  2269. if (write_reg(misc_info->client, BT532_DND_N_COUNT,
  2270. SEC_DND_N_COUNT) != I2C_SUCCESS)
  2271. printk(KERN_INFO "[zinitix_touch] TEST Mode : "
  2272. "Fail to set BT532_DND_N_COUNT %d.\n", SEC_DND_N_COUNT);
  2273. if (write_reg(misc_info->client, BT532_DND_U_COUNT,
  2274. SEC_DND_U_COUNT) != I2C_SUCCESS)
  2275. printk(KERN_INFO "[zinitix_touch] TEST Mode : "
  2276. "Fail to set BT532_DND_U_COUNT %d.\n", SEC_DND_U_COUNT);
  2277. if (write_reg(misc_info->client, BT532_AFE_FREQUENCY,
  2278. SEC_DND_FREQUENCY) != I2C_SUCCESS)
  2279. printk(KERN_INFO "[zinitix_touch] TEST Mode : "
  2280. "Fail to set BT532_AFE_FREQUENCY %d.\n", SEC_DND_FREQUENCY);
  2281. }
  2282. if (value == TOUCH_PDND_MODE) {
  2283. #ifndef ZINITIX_NEW_TA_COVER_REGISTER_0x11F
  2284. read_data(misc_info->client, 0x011e, (u8 *)&reg_val, 2);
  2285. zinitix_bit_clr(reg_val, 1);
  2286. write_reg(misc_info->client, 0x011e, reg_val);
  2287. #endif
  2288. if (write_reg(misc_info->client, BT532_DND_N_COUNT,
  2289. SEC_PDND_N_COUNT) != I2C_SUCCESS)
  2290. printk(KERN_INFO "[zinitix_touch] TEST Mode : "
  2291. "Fail to set BT532_DND_N_COUNT %d.\n", SEC_PDND_N_COUNT);
  2292. if (write_reg(misc_info->client, BT532_DND_U_COUNT,
  2293. SEC_PDND_U_COUNT) != I2C_SUCCESS)
  2294. printk(KERN_INFO "[zinitix_touch] TEST Mode : "
  2295. "Fail to set BT532_DND_U_COUNT %d.\n", SEC_PDND_U_COUNT);
  2296. if (write_reg(misc_info->client, BT532_AFE_FREQUENCY,
  2297. SEC_PDND_FREQUENCY) != I2C_SUCCESS)
  2298. printk(KERN_INFO "[zinitix_touch] TEST Mode : "
  2299. "Fail to set BT532_AFE_FREQUENCY %d.\n", SEC_PDND_FREQUENCY);
  2300. }
  2301. else if(misc_info->touch_mode == TOUCH_DND_MODE || misc_info->touch_mode == TOUCH_PDND_MODE) {
  2302. #ifndef ZINITIX_NEW_TA_COVER_REGISTER_0x11F
  2303. bt532_set_ta_status(misc_info);
  2304. #endif
  2305. if (write_reg(misc_info->client, BT532_DND_SHIFT_VALUE,
  2306. misc_info->cap_info.shift_value) != I2C_SUCCESS)
  2307. dev_err(&misc_info->client->dev, "Failed to set DND_SHIFT_VALUE\n");
  2308. if (write_reg(misc_info->client, BT532_DND_N_COUNT,
  2309. misc_info->cap_info.N_cnt) != I2C_SUCCESS)
  2310. printk(KERN_INFO "[zinitix_touch] TEST Mode : "
  2311. "Fail to reset BT532_AFE_FREQUENCY %d.\n",
  2312. misc_info->cap_info.N_cnt);
  2313. if (write_reg(misc_info->client, BT532_DND_U_COUNT,
  2314. misc_info->cap_info.u_cnt) != I2C_SUCCESS)
  2315. printk(KERN_INFO "[zinitix_touch] TEST Mode : "
  2316. "Fail to reset BT532_DND_U_COUNT %d.\n",
  2317. misc_info->cap_info.u_cnt);
  2318. if (write_reg(misc_info->client, BT532_AFE_FREQUENCY,
  2319. misc_info->cap_info.afe_frequency) != I2C_SUCCESS)
  2320. printk(KERN_INFO "[zinitix_touch] TEST Mode : "
  2321. "Fail to reset BT532_AFE_FREQUENCY %d.\n",
  2322. misc_info->cap_info.afe_frequency);
  2323. }
  2324. if (value == TOUCH_SEC_MODE)
  2325. misc_info->touch_mode = TOUCH_POINT_MODE;
  2326. else
  2327. misc_info->touch_mode = value;
  2328. printk(KERN_INFO "[zinitix_touch] tsp_set_testmode, "
  2329. "touchkey_testmode = %d\r\n", misc_info->touch_mode);
  2330. if (misc_info->touch_mode != TOUCH_POINT_MODE) {
  2331. if (write_reg(misc_info->client, BT532_DELAY_RAW_FOR_HOST,
  2332. RAWDATA_DELAY_FOR_HOST) != I2C_SUCCESS)
  2333. zinitix_printk("Fail to set BT532_DELAY_RAW_FOR_HOST.\r\n");
  2334. }
  2335. if (write_reg(misc_info->client, BT532_TOUCH_MODE,
  2336. misc_info->touch_mode) != I2C_SUCCESS)
  2337. printk(KERN_INFO "[zinitix_touch] TEST Mode : "
  2338. "Fail to set ZINITX_TOUCH_MODE %d.\r\n", misc_info->touch_mode);
  2339. /* clear garbage data */
  2340. for (i = 0; i < 10; i++) {
  2341. mdelay(20);
  2342. write_cmd(misc_info->client, BT532_CLEAR_INT_STATUS_CMD);
  2343. }
  2344. misc_info->work_state = NOTHING;
  2345. enable_irq(misc_info->irq);
  2346. up(&misc_info->work_lock);
  2347. return 1;
  2348. }
  2349. static int ts_upgrade_sequence(const u8 *firmware_data)
  2350. {
  2351. disable_irq(misc_info->irq);
  2352. down(&misc_info->work_lock);
  2353. misc_info->work_state = UPGRADE;
  2354. #if ESD_TIMER_INTERVAL
  2355. esd_timer_stop(misc_info);
  2356. #endif
  2357. zinitix_debug_msg("clear all reported points\r\n");
  2358. clear_report_data(misc_info);
  2359. printk(KERN_INFO "start upgrade firmware\n");
  2360. if (ts_upgrade_firmware(misc_info,
  2361. firmware_data,
  2362. misc_info->cap_info.ic_fw_size) == false) {
  2363. enable_irq(misc_info->irq);
  2364. misc_info->work_state = NOTHING;
  2365. up(&misc_info->work_lock);
  2366. return -1;
  2367. }
  2368. if (init_touch(misc_info) == false) {
  2369. enable_irq(misc_info->irq);
  2370. misc_info->work_state = NOTHING;
  2371. up(&misc_info->work_lock);
  2372. return -1;
  2373. }
  2374. #if ESD_TIMER_INTERVAL
  2375. esd_timer_start(CHECK_ESD_TIMER, misc_info);
  2376. #if defined(TSP_VERBOSE_DEBUG)
  2377. dev_info(&misc_info->client->dev, "Started esd timer\n");
  2378. #endif
  2379. #endif
  2380. enable_irq(misc_info->irq);
  2381. misc_info->work_state = NOTHING;
  2382. up(&misc_info->work_lock);
  2383. return 0;
  2384. }
  2385. #ifdef SEC_FACTORY_TEST
  2386. static inline void set_cmd_result(struct bt532_ts_info *info, char *buff, int len)
  2387. {
  2388. strncat(info->factory_info->cmd_result, buff, len);
  2389. }
  2390. static inline void set_default_result(struct bt532_ts_info *info)
  2391. {
  2392. char delim = ':';
  2393. memset(info->factory_info->cmd_result, 0x00, ARRAY_SIZE(info->factory_info->cmd_result));
  2394. memcpy(info->factory_info->cmd_result, info->factory_info->cmd, strlen(info->factory_info->cmd));
  2395. strncat(info->factory_info->cmd_result, &delim, 1);
  2396. }
  2397. #define MAX_FW_PATH 255
  2398. #define TSP_FW_FILENAME "zinitix_fw.bin"
  2399. static void fw_update(void *device_data)
  2400. {
  2401. struct bt532_ts_info *info = (struct bt532_ts_info *)device_data;
  2402. struct i2c_client *client = info->client;
  2403. int ret = 0;
  2404. const u8 *buff = 0;
  2405. mm_segment_t old_fs = {0};
  2406. struct file *fp = NULL;
  2407. long fsize = 0, nread = 0;
  2408. char fw_path[MAX_FW_PATH + 1];
  2409. char result[16] = {0};
  2410. set_default_result(info);
  2411. switch (info->factory_info->cmd_param[0]) {
  2412. case BUILT_IN:
  2413. ret = ts_upgrade_sequence((u8 *)m_firmware_data);
  2414. if(ret<0) {
  2415. info->factory_info->cmd_state = 3;
  2416. return;
  2417. }
  2418. break;
  2419. case UMS:
  2420. old_fs = get_fs();
  2421. set_fs(get_ds());
  2422. snprintf(fw_path, MAX_FW_PATH, "/sdcard/%s", TSP_FW_FILENAME);
  2423. fp = filp_open(fw_path, O_RDONLY, 0);
  2424. if (IS_ERR(fp)) {
  2425. dev_err(&client->dev,
  2426. "file %s open error:%d\n", fw_path, (s32)fp);
  2427. info->factory_info->cmd_state = 3;
  2428. goto err_open;
  2429. }
  2430. fsize = fp->f_path.dentry->d_inode->i_size;
  2431. if (fsize != info->cap_info.ic_fw_size) {
  2432. dev_err(&client->dev, "invalid fw size!!\n");
  2433. info->factory_info->cmd_state = 3;
  2434. goto err_open;
  2435. }
  2436. buff = kzalloc((size_t)fsize, GFP_KERNEL);
  2437. if (!buff) {
  2438. dev_err(&client->dev, "failed to alloc buffer for fw\n");
  2439. info->factory_info->cmd_state = 3;
  2440. goto err_alloc;
  2441. }
  2442. nread = vfs_read(fp, (char __user *)buff, fsize, &fp->f_pos);
  2443. if (nread != fsize) {
  2444. info->factory_info->cmd_state = 3;
  2445. goto err_fw_size;
  2446. }
  2447. filp_close(fp, current->files);
  2448. set_fs(old_fs);
  2449. dev_info(&client->dev, "ums fw is loaded!!\n");
  2450. ret = ts_upgrade_sequence((u8 *)buff);
  2451. if(ret<0) {
  2452. kfree(buff);
  2453. info->factory_info->cmd_state = 3;
  2454. return;
  2455. }
  2456. break;
  2457. default:
  2458. dev_err(&client->dev, "invalid fw file type!!\n");
  2459. goto not_support;
  2460. }
  2461. info->factory_info->cmd_state = 2;
  2462. snprintf(result, sizeof(result) , "%s", "OK");
  2463. set_cmd_result(info, result,
  2464. strnlen(result, sizeof(result)));
  2465. if (fp != NULL) {
  2466. err_fw_size:
  2467. kfree(buff);
  2468. err_alloc:
  2469. filp_close(fp, NULL);
  2470. err_open:
  2471. set_fs(old_fs);
  2472. }
  2473. not_support:
  2474. snprintf(result, sizeof(result) , "%s", "NG");
  2475. set_cmd_result(info, result, strnlen(result, sizeof(result)));
  2476. return;
  2477. }
  2478. static void get_fw_ver_bin(void *device_data)
  2479. {
  2480. struct bt532_ts_info *info = (struct bt532_ts_info *)device_data;
  2481. struct i2c_client *client = info->client;
  2482. struct tsp_factory_info *finfo = info->factory_info;
  2483. u16 fw_version, fw_minor_version, reg_version, hw_id, vendor_id;
  2484. u32 version, length;
  2485. set_default_result(info);
  2486. /* To Do */
  2487. /* modify m_firmware_data */
  2488. fw_version = (u16)(m_firmware_data[52] | (m_firmware_data[53] << 8));
  2489. fw_minor_version = (u16)(m_firmware_data[56] | (m_firmware_data[57] << 8));
  2490. reg_version = (u16)(m_firmware_data[60] | (m_firmware_data[61] << 8));
  2491. hw_id = (u16)(m_firmware_data[0x6b12] | (m_firmware_data[0x6b13] << 8));
  2492. vendor_id = ntohs(*(u16 *)&m_firmware_data[0x6b22]);
  2493. version = (u32)((u32)(hw_id & 0xff) << 16) | ((fw_version & 0xf ) << 12)
  2494. | ((fw_minor_version & 0xf) << 8) | (reg_version & 0xff);
  2495. #if !defined(CONFIG_SEC_DEGAS_PROJECT)
  2496. config_version = version;
  2497. #endif
  2498. length = sizeof(vendor_id);
  2499. snprintf(finfo->cmd_buff, length + 1, "%s", (u8 *)&vendor_id);
  2500. snprintf(finfo->cmd_buff + length, sizeof(finfo->cmd_buff) - length,
  2501. "%06X", version);
  2502. set_cmd_result(info, finfo->cmd_buff,
  2503. strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
  2504. finfo->cmd_state = OK;
  2505. dev_info(&client->dev, "%s: %s(%d)\n", __func__, finfo->cmd_buff,
  2506. strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
  2507. return;
  2508. }
  2509. static void get_fw_ver_ic(void *device_data)
  2510. {
  2511. struct bt532_ts_info *info = (struct bt532_ts_info *)device_data;
  2512. struct i2c_client *client = info->client;
  2513. struct tsp_factory_info *finfo = info->factory_info;
  2514. u16 fw_version, fw_minor_version, reg_version, hw_id, vendor_id;
  2515. u32 version, length;
  2516. set_default_result(info);
  2517. fw_version = info->cap_info.fw_version;
  2518. fw_minor_version = info->cap_info.fw_minor_version;
  2519. reg_version = info->cap_info.reg_data_version;
  2520. hw_id = info->cap_info.hw_id;
  2521. vendor_id = ntohs(info->cap_info.vendor_id);
  2522. version = (u32)((u32)(hw_id & 0xff) << 16) | ((fw_version & 0xf) << 12)
  2523. | ((fw_minor_version & 0xf) << 8) | (reg_version & 0xff);
  2524. length = sizeof(vendor_id);
  2525. snprintf(finfo->cmd_buff, length + 1, "%s", (u8 *)&vendor_id);
  2526. snprintf(finfo->cmd_buff + length, sizeof(finfo->cmd_buff) - length,
  2527. "%06X", version);
  2528. set_cmd_result(info, finfo->cmd_buff,
  2529. strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
  2530. finfo->cmd_state = OK;
  2531. dev_info(&client->dev, "%s: %s(%d)\n", __func__, finfo->cmd_buff,
  2532. strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
  2533. return;
  2534. }
  2535. static void get_threshold(void *device_data)
  2536. {
  2537. struct bt532_ts_info *info = (struct bt532_ts_info *)device_data;
  2538. struct i2c_client *client = info->client;
  2539. struct tsp_factory_info *finfo = info->factory_info;
  2540. set_default_result(info);
  2541. snprintf(finfo->cmd_buff, sizeof(finfo->cmd_buff),
  2542. "%d", info->cap_info.threshold);
  2543. set_cmd_result(info, finfo->cmd_buff,
  2544. strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
  2545. finfo->cmd_state = OK;
  2546. dev_info(&client->dev, "%s: %s(%d)\n", __func__, finfo->cmd_buff,
  2547. strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
  2548. return;
  2549. }
  2550. static void module_off_master(void *device_data)
  2551. {
  2552. return;
  2553. }
  2554. static void module_on_master(void *device_data)
  2555. {
  2556. return;
  2557. }
  2558. static void module_off_slave(void *device_data)
  2559. {
  2560. return;
  2561. }
  2562. static void module_on_slave(void *device_data)
  2563. {
  2564. return;
  2565. }
  2566. static void get_module_vendor(void *device_data)
  2567. {
  2568. struct bt532_ts_info *info = (struct bt532_ts_info *)device_data;
  2569. struct i2c_client *client = info->client;
  2570. struct tsp_factory_info *fdata = info->factory_info;
  2571. char buff[16] = {0};
  2572. int val,val2;
  2573. set_default_result(info);
  2574. if (!(gpio_get_value(info->pdata->tsp_en_gpio)) ) {
  2575. dev_err(&client->dev, "%s: [ERROR] Touch is stopped\n",
  2576. __func__);
  2577. snprintf(buff, sizeof(buff), "%s", "TSP turned off");
  2578. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  2579. fdata->cmd_state = NOT_APPLICABLE;
  2580. return;
  2581. }
  2582. if (info->pdata->tsp_vendor1 > 0 && info->pdata->tsp_vendor2 > 0 ) {
  2583. gpio_tlmm_config(GPIO_CFG(info->pdata->tsp_vendor1, 0,
  2584. GPIO_CFG_INPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), 1);
  2585. gpio_tlmm_config(GPIO_CFG(info->pdata->tsp_vendor2, 0,
  2586. GPIO_CFG_INPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), 1);
  2587. val = gpio_get_value(info->pdata->tsp_vendor1);
  2588. val2 = gpio_get_value(info->pdata->tsp_vendor2);
  2589. dev_info(&info->client->dev,
  2590. "%s: TSP_ID: %d[%d]%d[%d]\n", __func__,
  2591. info->pdata->tsp_vendor1, val,info->pdata->tsp_vendor2, val2);
  2592. snprintf(buff, sizeof(buff), "%s,%d%d", tostring(OK), val,val2);
  2593. fdata->cmd_state = OK;
  2594. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  2595. return;
  2596. }
  2597. snprintf(buff, sizeof(buff), "%s", tostring(NG));
  2598. fdata->cmd_state = FAIL;
  2599. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  2600. }
  2601. #define BT532_VENDOR_NAME "ZINITIX"
  2602. static void get_chip_vendor(void *device_data)
  2603. {
  2604. struct bt532_ts_info *info = (struct bt532_ts_info *)device_data;
  2605. struct i2c_client *client = info->client;
  2606. struct tsp_factory_info *finfo = info->factory_info;
  2607. set_default_result(info);
  2608. snprintf(finfo->cmd_buff, sizeof(finfo->cmd_buff),
  2609. "%s", BT532_VENDOR_NAME);
  2610. set_cmd_result(info, finfo->cmd_buff,
  2611. strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
  2612. finfo->cmd_state = OK;
  2613. dev_info(&client->dev, "%s: %s(%d)\n", __func__, finfo->cmd_buff,
  2614. strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
  2615. return;
  2616. }
  2617. static void get_config_ver(void *device_data)
  2618. {
  2619. struct bt532_ts_info *info = (struct bt532_ts_info *)device_data;
  2620. struct i2c_client *client = info->client;
  2621. struct tsp_factory_info *finfo = info->factory_info;
  2622. const char *model_name = info->pdata->pname;
  2623. set_default_result(info);
  2624. #if !defined(CONFIG_SEC_DEGAS_PROJECT)
  2625. snprintf(finfo->cmd_buff, sizeof(finfo->cmd_buff),"%s_ZI_%x", model_name,config_version);
  2626. #else
  2627. snprintf(finfo->cmd_buff, sizeof(finfo->cmd_buff),"%s_ZI_%s", model_name,CONFIG_DATE);
  2628. #endif
  2629. set_cmd_result(info, finfo->cmd_buff,
  2630. strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
  2631. finfo->cmd_state = OK;
  2632. dev_info(&client->dev, "%s: %s(%d)\n", __func__, finfo->cmd_buff,
  2633. strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
  2634. return;
  2635. }
  2636. #if defined(USE_ACTIVE_REPORT_RATE)
  2637. static void report_rate(void *device_data)
  2638. {
  2639. struct bt532_ts_info *info = (struct bt532_ts_info *)device_data;
  2640. struct i2c_client *client = info->client;
  2641. struct tsp_factory_info *finfo = info->factory_info;
  2642. int report_rate_cmd;
  2643. if((info->work_state == SUSPEND) || (info->work_state == PROBE)) {
  2644. dev_err(&client->dev, "%s: probe is not done or suspend mode work_state : %d \n",
  2645. __func__,info->work_state);
  2646. return;
  2647. }
  2648. set_default_result(info);
  2649. if ((finfo->cmd_param[0] < 0) ||
  2650. (finfo->cmd_param[0] > 2)) {
  2651. dev_err(&client->dev, "%s: parameter %d is wrong\n",
  2652. __func__, finfo->cmd_param[0]);
  2653. return;
  2654. }
  2655. report_rate_cmd = finfo->cmd_param[0];
  2656. ts_lpm_level_set(report_rate_cmd);
  2657. set_cmd_result(info, finfo->cmd_buff,
  2658. strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
  2659. finfo->cmd_state = OK;
  2660. dev_info(&client->dev, "%s: %s(%d)\n", __func__, finfo->cmd_buff,
  2661. strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
  2662. }
  2663. #endif
  2664. #define BT532_CHIP_NAME "BT532"
  2665. static void get_chip_name(void *device_data)
  2666. {
  2667. struct bt532_ts_info *info = (struct bt532_ts_info *)device_data;
  2668. struct i2c_client *client = info->client;
  2669. struct tsp_factory_info *finfo = info->factory_info;
  2670. set_default_result(info);
  2671. snprintf(finfo->cmd_buff, sizeof(finfo->cmd_buff), "%s", BT532_CHIP_NAME);
  2672. set_cmd_result(info, finfo->cmd_buff,
  2673. strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
  2674. finfo->cmd_state = OK;
  2675. dev_info(&client->dev, "%s: %s(%d)\n", __func__, finfo->cmd_buff,
  2676. strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
  2677. return;
  2678. }
  2679. static void get_x_num(void *device_data)
  2680. {
  2681. struct bt532_ts_info *info = (struct bt532_ts_info *)device_data;
  2682. struct i2c_client *client = info->client;
  2683. struct tsp_factory_info *finfo = info->factory_info;
  2684. set_default_result(info);
  2685. snprintf(finfo->cmd_buff, sizeof(finfo->cmd_buff),
  2686. "%u", info->cap_info.x_node_num);
  2687. set_cmd_result(info, finfo->cmd_buff,
  2688. strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
  2689. finfo->cmd_state = OK;
  2690. dev_info(&client->dev, "%s: %s(%d)\n", __func__, finfo->cmd_buff,
  2691. strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
  2692. return;
  2693. }
  2694. static void get_y_num(void *device_data)
  2695. {
  2696. struct bt532_ts_info *info = (struct bt532_ts_info *)device_data;
  2697. struct i2c_client *client = info->client;
  2698. struct tsp_factory_info *finfo = info->factory_info;
  2699. set_default_result(info);
  2700. snprintf(finfo->cmd_buff, sizeof(finfo->cmd_buff),
  2701. "%u", info->cap_info.y_node_num);
  2702. set_cmd_result(info, finfo->cmd_buff,
  2703. strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
  2704. finfo->cmd_state = OK;
  2705. dev_info(&client->dev, "%s: %s(%d)\n", __func__, finfo->cmd_buff,
  2706. strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
  2707. return;
  2708. }
  2709. static void not_support_cmd(void *device_data)
  2710. {
  2711. struct bt532_ts_info *info = (struct bt532_ts_info *)device_data;
  2712. struct i2c_client *client = info->client;
  2713. struct tsp_factory_info *finfo = info->factory_info;
  2714. set_default_result(info);
  2715. sprintf(finfo->cmd_buff, "%s", "NA");
  2716. set_cmd_result(info, finfo->cmd_buff,
  2717. strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
  2718. info->factory_info->cmd_state = NOT_APPLICABLE;
  2719. dev_info(&client->dev, "%s: \"%s(%d)\"\n", __func__, finfo->cmd_buff,
  2720. strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
  2721. return;
  2722. }
  2723. static void run_reference_read(void *device_data)
  2724. {
  2725. struct bt532_ts_info *info = (struct bt532_ts_info *)device_data;
  2726. struct i2c_client *client = info->client;
  2727. struct tsp_factory_info *finfo = info->factory_info;
  2728. struct tsp_raw_data *raw_data = info->raw_data;
  2729. u32 min, max;
  2730. s32 i, j;
  2731. set_default_result(info);
  2732. ts_set_touchmode(TOUCH_DND_MODE);
  2733. get_raw_data(info, (u8 *)raw_data->ref_data, 10);
  2734. ts_set_touchmode(TOUCH_POINT_MODE);
  2735. min = raw_data->ref_data[0];
  2736. max = raw_data->ref_data[0];
  2737. for(i = 0; i < info->cap_info.x_node_num; i++)
  2738. {
  2739. for(j = 0; j < info->cap_info.y_node_num; j++)
  2740. {
  2741. /*pr_info("ref_data : %d ",
  2742. raw_data->ref_data[i * info->cap_info.y_node_num + j]);*/
  2743. if (raw_data->ref_data[i * info->cap_info.y_node_num + j] < min &&
  2744. raw_data->ref_data[i * info->cap_info.y_node_num + j] != 0)
  2745. min = raw_data->ref_data[i * info->cap_info.y_node_num + j];
  2746. if (raw_data->ref_data[i * info->cap_info.y_node_num + j] > max)
  2747. max = raw_data->ref_data[i * info->cap_info.y_node_num + j];
  2748. }
  2749. /*pr_info("\n");*/
  2750. }
  2751. snprintf(finfo->cmd_buff, sizeof(finfo->cmd_buff), "%d,%d\n", min, max);
  2752. set_cmd_result(info, finfo->cmd_buff,
  2753. strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
  2754. finfo->cmd_state = OK;
  2755. dev_info(&client->dev, "%s: \"%s\"(%d)\n", __func__, finfo->cmd_buff,
  2756. strlen(finfo->cmd_buff));
  2757. return;
  2758. }
  2759. static bool run_reference_PDiff_read(void *device_data, const u16 h_diff[][17], const u16 v_diff[][18], int bHidden1, int bMenu, int bBack, int bHidden2 ) //DND
  2760. {
  2761. struct bt532_ts_info *info = (struct bt532_ts_info *)device_data;
  2762. int i, j, diff_val, pre_val, next_val, x_num, y_num, nButton;
  2763. bool pass = true;
  2764. int buttons[4] = {bHidden1,bMenu, bBack, bHidden2};
  2765. #if 1
  2766. char print_diff[29*18]={0,};
  2767. #endif
  2768. ts_set_touchmode(TOUCH_PDND_MODE);
  2769. get_raw_data(info, (u8 *)info->dnd_data, 10);
  2770. ts_set_touchmode(TOUCH_POINT_MODE);
  2771. x_num = info->cap_info.x_node_num;
  2772. y_num = info->cap_info.y_node_num;
  2773. printk("%s : ++++++ DND SPEC +++++++++\n",__func__);
  2774. for(i = 0; i < x_num; i++)
  2775. {
  2776. printk("%s : ",__func__);
  2777. for(j = 0; j < y_num; j++)
  2778. {
  2779. printk("%5d ", info->dnd_data[i*y_num+j]);
  2780. }
  2781. printk("\n");
  2782. }
  2783. printk("%s : ------- DND SPEC ----------\n",__func__);
  2784. printk("%s : TSP Diff test scale factor = %d\n", __func__, info->ref_scale_factor);
  2785. printk("%s : H Diff start\n",__func__);
  2786. //H DIff
  2787. info->hdiff_max_x = info->hdiff_max_y = info->hdiff_min_x = info->hdiff_min_y = 0;
  2788. info->hdiff_max_val =-32768;
  2789. info->hdiff_min_val =32767;
  2790. for(i = 0; i < x_num - 1; i++)
  2791. {
  2792. for(j = 0; j <y_num-1; j++)
  2793. {
  2794. //printk("%d ", info->dnd_data[i*info->cap_info.y_node_num+j]);
  2795. next_val = info->dnd_data[(i*y_num)+(j+1)];
  2796. pre_val = info->dnd_data[(i*y_num)+j];
  2797. diff_val = (next_val > pre_val)?(next_val - pre_val):(pre_val - next_val);
  2798. pre_val = (info->ref_scale_factor == 100)?((s16)h_diff[i][j]):((s16)(((s32)h_diff[i][j] * info->ref_scale_factor) /100));
  2799. if(diff_val > pre_val)
  2800. pass = false;
  2801. #if 1
  2802. print_diff[i*y_num+j] = diff_val;
  2803. #endif
  2804. if(info->hdiff_max_val < diff_val-pre_val) {
  2805. info->hdiff_max_val = diff_val-pre_val;
  2806. info->hdiff_max_x = i;
  2807. info->hdiff_max_y= j+1;
  2808. }
  2809. if(info->hdiff_min_val > diff_val - pre_val) {
  2810. info->hdiff_min_val = diff_val - pre_val;
  2811. info->hdiff_min_x = i;
  2812. info->hdiff_min_y= j+1;
  2813. }
  2814. }
  2815. //printk("\n");
  2816. }
  2817. #if defined(PDIFF_DEBUG)
  2818. printk("%s : ++++++ h_diff SPEC +++++++++\n",__func__);
  2819. for(i = 0; i < x_num-1; i++){
  2820. printk("%s : ",__func__);
  2821. for(j = 0; j < y_num-1; j++)
  2822. printk("%5d ",(u16)h_diff[i][j]);
  2823. printk("\n");
  2824. }
  2825. printk("%s : ------- h_diff SPEC ----------\n",__func__);
  2826. printk("%s : ++++++ calculated h_diff SPEC +++++++++\n",__func__);
  2827. for(i = 0; i < x_num-1; i++){
  2828. printk("%s : ",__func__);
  2829. for(j = 0; j < y_num-1; j++)
  2830. printk("%5d ",print_diff[i*y_num+j]);
  2831. printk("\n");
  2832. }
  2833. printk("%s : ------- calculated h_diff SPEC ----------\n",__func__);
  2834. #endif
  2835. printk("%s :",__func__);
  2836. if(pass)
  2837. printk("H Diff pass\n");
  2838. else
  2839. printk("H Diff fail\n");
  2840. printk("%s : V Diff start\n",__func__);
  2841. info->hdiff_max_x = info->hdiff_max_y = info->hdiff_min_x = info->hdiff_min_y = 0;
  2842. info->vdiff_max_val =-32768;
  2843. info->vdiff_min_val =32767;
  2844. //V DIff View
  2845. for(i=0; i < x_num-2; i++)
  2846. {
  2847. for(j=0; j<y_num; j++)
  2848. {
  2849. //printk("%d ", info->dnd_data[i*info->cap_info.y_node_num+j]);
  2850. next_val = info->dnd_data[(i*y_num)+j];
  2851. pre_val = info->dnd_data[(i*y_num)+j+y_num];
  2852. diff_val = (next_val > pre_val)?(next_val - pre_val):(pre_val - next_val);
  2853. pre_val = (info->ref_scale_factor == 100)?((s16)v_diff[i][j]):((s16)(((s32)v_diff[i][j] * info->ref_scale_factor) /100));
  2854. if(diff_val > pre_val)
  2855. pass = false;
  2856. #if 1
  2857. print_diff[i*y_num+j] = diff_val;
  2858. #endif
  2859. if(info->vdiff_max_val < diff_val - pre_val) {
  2860. info->vdiff_max_val = diff_val -pre_val;
  2861. info->vdiff_max_x = i;
  2862. info->vdiff_max_y= j+1;
  2863. }
  2864. if(info->vdiff_min_val > diff_val - pre_val) {
  2865. info->vdiff_min_val = diff_val - pre_val;
  2866. info->vdiff_min_x = i;
  2867. info->vdiff_min_y= j+1;
  2868. }
  2869. }
  2870. //printk("\n");
  2871. }
  2872. printk("%s : ",__func__);
  2873. if(pass)
  2874. printk("V Diff view pass\n");
  2875. else
  2876. printk("V Diff view fail\n");
  2877. #if 1
  2878. printk(" : ++++++ v_diff SPEC +++++++++\n");
  2879. for(i=0; i < x_num-2; i++){
  2880. printk("%s : ",__func__);
  2881. for(j=0; j < y_num; j++)
  2882. printk("%5d ",(u16)v_diff[i][j]);
  2883. printk("\n");
  2884. }
  2885. printk("%s : ------- v_diff SPEC ----------\n",__func__);
  2886. printk("%s : ++++++ calculated v_diff SPEC +++++++++\n",__func__);
  2887. for(i=0; i < x_num-2; i++){
  2888. printk("%s : ",__func__);
  2889. for(j=0; j < y_num; j++)
  2890. printk("%5d ",print_diff[i*y_num+j]);
  2891. printk("\n");
  2892. }
  2893. printk("%s : ------- calculated v_diff SPEC ----------\n",__func__);
  2894. #endif
  2895. //V DIff button
  2896. if ( info->cap_info.button_num)
  2897. {
  2898. printk("%s : TSP Button scale = %d\n", __func__, info->ref_scale_factor);
  2899. printk("%s : TSP Button Diff Spec. = %d %d %d %d\n", __func__,
  2900. v_diff[x_num-2][buttons[0]], v_diff[x_num-2][buttons[1]],
  2901. v_diff[x_num-2][buttons[2]], v_diff[x_num-2][buttons[3]]);
  2902. for(i = 0; i < 4; i++)
  2903. {
  2904. nButton = buttons[i];
  2905. if(nButton < 0)
  2906. continue;
  2907. next_val = info->dnd_data[(x_num-1)*y_num+nButton];
  2908. pre_val = info->dnd_data[(x_num-2)*y_num+nButton];
  2909. diff_val = (next_val > pre_val)?(next_val - pre_val):(pre_val - next_val);
  2910. pre_val = (info->ref_scale_factor == 100)?( (s16)v_diff[x_num-2][nButton]+info->ref_btn_option): \
  2911. ( (s16)(((s32)v_diff[x_num-2][nButton]*info->ref_scale_factor)/100)+info->ref_btn_option);
  2912. if(diff_val > pre_val) {
  2913. pass = false;
  2914. if(info->vdiff_max_val < diff_val - pre_val) {
  2915. info->vdiff_max_val = diff_val - pre_val;
  2916. info->vdiff_max_x = x_num - 1;
  2917. info->vdiff_max_y= nButton;
  2918. }
  2919. if(info->vdiff_min_val >diff_val - pre_val) {
  2920. info->vdiff_min_val = diff_val-pre_val;
  2921. info->vdiff_min_x = x_num - 1;
  2922. info->vdiff_min_y= nButton;
  2923. }
  2924. }
  2925. #if defined(PDIFF_DEBUG)
  2926. printk("%s : ",__func__);
  2927. printk("buttons[%d]'s diff_val is %d\n", i, diff_val);
  2928. #endif
  2929. }
  2930. }
  2931. printk("%s : ",__func__);
  2932. if(pass)
  2933. printk("Button Diff pass\n");
  2934. else
  2935. printk("Button Diff fail\n");
  2936. return pass;
  2937. }
  2938. static void run_reference_PDiff(void *device_data)
  2939. {
  2940. struct bt532_ts_info *info = (struct bt532_ts_info *)device_data;
  2941. struct tsp_factory_info *finfo = info->factory_info;
  2942. char buff[16] = {0};
  2943. bool check;
  2944. finfo->cmd_state = 1;
  2945. set_default_result(info);
  2946. printk("run_ref_diff check hw_id = 0x%04X\n", info->cap_info.hw_id);
  2947. #ifdef NOT_SUPPORTED_TOUCH_DUMMY_KEY
  2948. check = run_reference_PDiff_read(device_data, dnd_h_diff_00, dnd_v_diff_00, -1, 4, 13, -1);
  2949. #else
  2950. check = run_reference_PDiff_read(device_data, dnd_h_diff_00, dnd_v_diff_00, 2, 4, 13, 15);
  2951. #endif
  2952. /*
  2953. if( info->cap_info.hw_id == TSP_HW_ID_INDEX_0) { // Check TSP FW ID
  2954. printk("HW_ID_INDEX_0\n");
  2955. check = run_reference_PDiff_read(device_data, dnd_h_diff_00, dnd_v_diff_00, 2, 4, 13, 15);
  2956. }
  2957. else if( info->cap_info.hw_id == TSP_HW_ID_INDEX_1){ // Check TSP FW ID
  2958. printk("HW_ID_INDEX_1\n");
  2959. check = run_reference_PDiff_read(device_data, dnd_h_diff_03, dnd_v_diff_03, 2, 4, 13, 15);
  2960. }
  2961. else{
  2962. printk("Module ETC\n");
  2963. check = run_reference_PDiff_read(device_data, dnd_h_diff_00, dnd_v_diff_00, 2, 4, 13, 15);
  2964. }
  2965. */
  2966. if(check) {
  2967. printk("diff pass\n");
  2968. sprintf(buff, "%s\n", "pass");
  2969. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  2970. finfo->cmd_state = 2;
  2971. }
  2972. else {
  2973. printk("diff fail\n");
  2974. sprintf(buff, "%s\n", "fail");
  2975. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  2976. finfo->cmd_state = 3;
  2977. }
  2978. }
  2979. static void get_reference(void *device_data)
  2980. {
  2981. struct bt532_ts_info *info = (struct bt532_ts_info *)device_data;
  2982. struct i2c_client *client = info->client;
  2983. struct tsp_factory_info *finfo = info->factory_info;
  2984. struct tsp_raw_data *raw_data = info->raw_data;
  2985. unsigned int val;
  2986. int x_node, y_node;
  2987. int node_num;
  2988. set_default_result(info);
  2989. x_node = finfo->cmd_param[0];
  2990. y_node = finfo->cmd_param[1];
  2991. if (x_node < 0 || x_node >= info->cap_info.x_node_num ||
  2992. y_node < 0 || y_node >= info->cap_info.y_node_num) {
  2993. snprintf(finfo->cmd_buff, sizeof(finfo->cmd_buff), "%s", "abnormal");
  2994. set_cmd_result(info, finfo->cmd_buff,
  2995. strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
  2996. info->factory_info->cmd_state = FAIL;
  2997. return;
  2998. }
  2999. node_num = x_node * info->cap_info.y_node_num + y_node;
  3000. val = raw_data->ref_data[node_num];
  3001. snprintf(finfo->cmd_buff, sizeof(finfo->cmd_buff), "%u", val);
  3002. set_cmd_result(info, finfo->cmd_buff,
  3003. strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
  3004. finfo->cmd_state = OK;
  3005. dev_info(&client->dev, "%s: %s(%d)\n", __func__, finfo->cmd_buff,
  3006. strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
  3007. return;
  3008. }
  3009. static void run_preference_read(void *device_data)
  3010. {
  3011. struct bt532_ts_info *info = (struct bt532_ts_info *)device_data;
  3012. struct i2c_client *client = info->client;
  3013. struct tsp_factory_info *finfo = info->factory_info;
  3014. struct tsp_raw_data *raw_data = info->raw_data;
  3015. u16 min, max;
  3016. s32 i, j;
  3017. set_default_result(info);
  3018. ts_set_touchmode(TOUCH_PDND_MODE);
  3019. get_raw_data(info, (u8 *)raw_data->pref_data, 10);
  3020. ts_set_touchmode(TOUCH_POINT_MODE);
  3021. min = 0xFFFF;
  3022. max = 0x0000;
  3023. for(i = 0; i < info->cap_info.x_node_num; i++)
  3024. {
  3025. for(j = 0; j < info->cap_info.y_node_num; j++)
  3026. {
  3027. /*pr_info("pref_data : %d ",
  3028. raw_data->pref_data[i * info->cap_info.y_node_num + j]);*/
  3029. if (raw_data->pref_data[i * info->cap_info.y_node_num + j] < min &&
  3030. raw_data->pref_data[i * info->cap_info.y_node_num + j] != 0)
  3031. min = raw_data->pref_data[i * info->cap_info.y_node_num + j];
  3032. if (raw_data->pref_data[i * info->cap_info.y_node_num + j] > max)
  3033. max = raw_data->pref_data[i * info->cap_info.y_node_num + j];
  3034. }
  3035. /*pr_info("\n");*/
  3036. }
  3037. snprintf(finfo->cmd_buff, sizeof(finfo->cmd_buff), "%d,%d\n", min, max);
  3038. set_cmd_result(info, finfo->cmd_buff,
  3039. strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
  3040. finfo->cmd_state = OK;
  3041. dev_info(&client->dev, "%s: \"%s\"(%d)\n", __func__, finfo->cmd_buff,
  3042. strlen(finfo->cmd_buff));
  3043. return;
  3044. }
  3045. static void get_preference(void *device_data)
  3046. {
  3047. struct bt532_ts_info *info = (struct bt532_ts_info *)device_data;
  3048. struct i2c_client *client = info->client;
  3049. struct tsp_factory_info *finfo = info->factory_info;
  3050. struct tsp_raw_data *raw_data = info->raw_data;
  3051. unsigned int val;
  3052. int x_node, y_node;
  3053. int node_num;
  3054. set_default_result(info);
  3055. x_node = finfo->cmd_param[0];
  3056. y_node = finfo->cmd_param[1];
  3057. if (x_node < 0 || x_node >= info->cap_info.x_node_num ||
  3058. y_node < 0 || y_node >= info->cap_info.y_node_num) {
  3059. snprintf(finfo->cmd_buff, sizeof(finfo->cmd_buff), "%s", "abnormal");
  3060. set_cmd_result(info, finfo->cmd_buff,
  3061. strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
  3062. info->factory_info->cmd_state = FAIL;
  3063. return;
  3064. }
  3065. node_num = x_node * info->cap_info.y_node_num + y_node;
  3066. val = raw_data->pref_data[node_num];
  3067. snprintf(finfo->cmd_buff, sizeof(finfo->cmd_buff), "%u", val);
  3068. set_cmd_result(info, finfo->cmd_buff,
  3069. strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
  3070. finfo->cmd_state = OK;
  3071. dev_info(&client->dev, "%s: %s(%d)\n", __func__, finfo->cmd_buff,
  3072. strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
  3073. return;
  3074. }
  3075. static void run_delta_read(void *device_data)
  3076. {
  3077. struct bt532_ts_info *info = (struct bt532_ts_info *)device_data;
  3078. struct i2c_client *client = info->client;
  3079. struct tsp_factory_info *finfo = info->factory_info;
  3080. struct tsp_raw_data *raw_data = info->raw_data;
  3081. s16 min, max;
  3082. s32 i, j;
  3083. set_default_result(info);
  3084. ts_set_touchmode(TOUCH_DELTA_MODE);
  3085. get_raw_data(info, (u8 *)(u8 *)raw_data->delta_data, 10);
  3086. ts_set_touchmode(TOUCH_POINT_MODE);
  3087. finfo->cmd_state = OK;
  3088. min = (s16)0x7FFF;
  3089. max = (s16)0x8000;
  3090. for(i = 0; i < info->cap_info.x_node_num; i++)
  3091. {
  3092. for(j = 0; j < info->cap_info.y_node_num; j++)
  3093. {
  3094. /*printk("delta_data : %d \n", raw_data->delta_data[j+i]);*/
  3095. if (raw_data->delta_data[i * info->cap_info.y_node_num + j] < min &&
  3096. raw_data->delta_data[i * info->cap_info.y_node_num + j] != 0)
  3097. min = raw_data->delta_data[i * info->cap_info.y_node_num + j];
  3098. if (raw_data->delta_data[i * info->cap_info.y_node_num + j] > max)
  3099. max = raw_data->delta_data[i * info->cap_info.y_node_num + j];
  3100. }
  3101. /*printk("\n");*/
  3102. }
  3103. snprintf(finfo->cmd_buff, sizeof(finfo->cmd_buff), "%d,%d\n", min, max);
  3104. set_cmd_result(info, finfo->cmd_buff,
  3105. strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
  3106. finfo->cmd_state = OK;
  3107. dev_info(&client->dev, "%s: \"%s\"(%d)\n", __func__, finfo->cmd_buff,
  3108. strlen(finfo->cmd_buff));
  3109. return;
  3110. }
  3111. static void get_delta(void *device_data)
  3112. {
  3113. struct bt532_ts_info *info = (struct bt532_ts_info *)device_data;
  3114. struct i2c_client *client = info->client;
  3115. struct tsp_factory_info *finfo = info->factory_info;
  3116. struct tsp_raw_data *raw_data = info->raw_data;
  3117. unsigned int val;
  3118. int x_node, y_node;
  3119. int node_num;
  3120. set_default_result(info);
  3121. x_node = finfo->cmd_param[0];
  3122. y_node = finfo->cmd_param[1];
  3123. if (x_node < 0 || x_node >= info->cap_info.x_node_num ||
  3124. y_node < 0 || y_node >= info->cap_info.y_node_num) {
  3125. snprintf(finfo->cmd_buff, sizeof(finfo->cmd_buff), "%s", "abnormal");
  3126. set_cmd_result(info, finfo->cmd_buff,
  3127. strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
  3128. info->factory_info->cmd_state = FAIL;
  3129. return;
  3130. }
  3131. node_num = x_node * info->cap_info.y_node_num + y_node;
  3132. val = raw_data->delta_data[node_num];
  3133. snprintf(finfo->cmd_buff, sizeof(finfo->cmd_buff), "%u", val);
  3134. set_cmd_result(info, finfo->cmd_buff,
  3135. strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
  3136. info->factory_info->cmd_state = OK;
  3137. dev_info(&client->dev, "%s: %s(%d)\n", __func__, finfo->cmd_buff,
  3138. strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
  3139. return;
  3140. }
  3141. static void cover_set(struct bt532_ts_info *info){
  3142. if(g_cover_state == COVER_OPEN){
  3143. zinitix_bit_clr(m_optional_mode, 2);
  3144. } else if(g_cover_state == COVER_CLOSED) {
  3145. zinitix_bit_set(m_optional_mode, 2);
  3146. }
  3147. if(info->work_state == SUSPEND || info->work_state == PROBE)
  3148. return;
  3149. bt532_set_optional_mode(info, true);
  3150. }
  3151. static void clear_cover_mode(void *device_data)
  3152. {
  3153. struct bt532_ts_info *info = (struct bt532_ts_info *)device_data;
  3154. struct tsp_factory_info *finfo = info->factory_info;
  3155. int arg = finfo->cmd_param[0];
  3156. set_default_result(info);
  3157. snprintf(finfo->cmd_buff, sizeof(finfo->cmd_buff), "%u",
  3158. (unsigned int) arg);
  3159. g_cover_state = arg;
  3160. cover_set(info);
  3161. dev_info(&info->client->dev, "COVER state = %d\n", g_cover_state);
  3162. set_cmd_result(info, finfo->cmd_buff,
  3163. strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
  3164. mutex_lock(&finfo->cmd_lock);
  3165. finfo->cmd_is_running = false;
  3166. mutex_unlock(&finfo->cmd_lock);
  3167. info->factory_info->cmd_state = OK;
  3168. return;
  3169. }
  3170. /*
  3171. static void run_intensity_read(void *device_data)
  3172. {
  3173. struct bt532_ts_info *info = (struct bt532_ts_info *)device_data;
  3174. set_default_result(info);
  3175. ts_set_touchmode(TOUCH_DND_MODE);
  3176. get_raw_data(info, (u8 *)info->dnd_data, 10);
  3177. ts_set_touchmode(TOUCH_POINT_MODE);
  3178. //////test////////////////////////////////////////////////////
  3179. int i,j;
  3180. for(i=0; i<30; i++)
  3181. {
  3182. for (j = 0; j < 18; j++)
  3183. printk("[TSP] info->dnd_data : %d ", info->dnd_data[j+i]);
  3184. printk("\n");
  3185. }
  3186. //////test////////////////////////////////////////////////////
  3187. info->factory_info->cmd_state = 2;
  3188. }
  3189. static void get_normal(void *device_data)
  3190. {
  3191. struct bt532_ts_info *info = (struct bt532_ts_info *)device_data;
  3192. char buff[16] = {0};
  3193. unsigned int val;
  3194. int x_node, y_node;
  3195. int node_num;
  3196. set_default_result(info);
  3197. x_node = info->factory_info->cmd_param[0];
  3198. y_node = info->factory_info->cmd_param[1];
  3199. if (x_node < 0 || x_node > info->cap_info.x_node_num ||
  3200. y_node < 0 || y_node > info->cap_info.y_node_num) {
  3201. snprintf(buff, sizeof(buff), "%s", "abnormal");
  3202. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  3203. info->factory_info->cmd_state = 3;
  3204. return;
  3205. }
  3206. node_num = x_node*info->cap_info.x_node_num + y_node;
  3207. val = info->normal_data[node_num];
  3208. snprintf(buff, sizeof(buff), "%u", val);
  3209. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  3210. info->factory_info->cmd_state = 2;
  3211. dev_info(&info->client->dev, "%s: %s(%d)\n", __func__,
  3212. buff, strnlen(buff, sizeof(buff)));
  3213. }
  3214. static void get_tkey_delta(void *device_data)
  3215. {
  3216. struct bt532_ts_info *info = (struct bt532_ts_info *)device_data;
  3217. char buff[16] = {0};
  3218. u16 val;
  3219. int btn_node;
  3220. int ret;
  3221. set_default_result(info);
  3222. btn_node = info->factory_info->cmd_param[0];
  3223. if (btn_node < 0 || btn_node > MAX_SUPPORTED_BUTTON_NUM)
  3224. goto err_out;
  3225. disable_irq(misc_info->irq);
  3226. down(&misc_info->work_lock);
  3227. if (misc_info->work_state != NOTHING) {
  3228. printk(KERN_INFO "other process occupied.. (%d)\n",
  3229. misc_info->work_state);
  3230. enable_irq(misc_info->irq);
  3231. up(&misc_info->work_lock);
  3232. goto err_out;
  3233. }
  3234. misc_info->work_state = SET_MODE;
  3235. ret = read_data(misc_info->client, BT532_BTN_WIDTH + btn_node, (u8*)&val, 2);
  3236. if (ret < 0) {
  3237. printk(KERN_INFO "read error..\n");
  3238. enable_irq(misc_info->irq);
  3239. misc_info->work_state = NOTHING;
  3240. up(&misc_info->work_lock);
  3241. goto err_out;
  3242. }
  3243. misc_info->work_state = NOTHING;
  3244. enable_irq(misc_info->irq);
  3245. up(&misc_info->work_lock);
  3246. snprintf(buff, sizeof(buff), "%u", val);
  3247. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  3248. info->factory_info->cmd_state = 2;
  3249. dev_info(&info->client->dev, "%s: %s(%d)\n", __func__,
  3250. buff, strnlen(buff, sizeof(buff)));
  3251. return;
  3252. err_out:
  3253. snprintf(buff, sizeof(buff), "%s", "abnormal");
  3254. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  3255. info->factory_info->cmd_state = 3;
  3256. }
  3257. static void get_intensity(void *device_data)
  3258. {
  3259. struct bt532_ts_info *info = (struct bt532_ts_info *)device_data;
  3260. char buff[16] = {0};
  3261. unsigned int val;
  3262. int x_node, y_node;
  3263. int node_num;
  3264. set_default_result(info);
  3265. x_node = info->factory_info->cmd_param[0];
  3266. y_node = info->factory_info->cmd_param[1];
  3267. if (x_node < 0 || x_node > info->cap_info.x_node_num ||
  3268. y_node < 0 || y_node > info->cap_info.y_node_num) {
  3269. snprintf(buff, sizeof(buff), "%s", "abnormal");
  3270. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  3271. info->factory_info->cmd_state = 3;
  3272. return;
  3273. }
  3274. node_num = x_node*info->cap_info.x_node_num + y_node;
  3275. val = info->dnd_data[node_num];
  3276. snprintf(buff, sizeof(buff), "%u", val);
  3277. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  3278. info->factory_info->cmd_state = 2;
  3279. dev_info(&info->client->dev, "%s: %s(%d)\n", __func__,
  3280. buff, strnlen(buff, sizeof(buff)));
  3281. }
  3282. static void run_normal_read(void *device_data)
  3283. {
  3284. struct bt532_ts_info *info = (struct bt532_ts_info *)device_data;
  3285. set_default_result(info);
  3286. ts_set_touchmode(TOUCH_NORMAL_MODE);
  3287. get_raw_data(info, (u8 *)info->normal_data, 10);
  3288. ts_set_touchmode(TOUCH_POINT_MODE);
  3289. info->factory_info->cmd_state = 2;
  3290. }
  3291. static void get_key_threshold(void *device_data)
  3292. {
  3293. struct bt532_ts_info *info = (struct bt532_ts_info *)device_data;
  3294. int ret = 0;
  3295. u16 threshold;
  3296. char buff[16] = {0};
  3297. set_default_result(info);
  3298. ret = read_data(misc_info->client, BT532_BUTTON_SENSITIVITY, (u8*)&threshold, 2);
  3299. if (ret < 0) {
  3300. snprintf(buff, sizeof(buff), "%s", "failed");
  3301. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  3302. info->factory_info->cmd_state = 3;
  3303. return;
  3304. }
  3305. snprintf(buff, sizeof(buff), "%u", threshold);
  3306. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  3307. info->factory_info->cmd_state = 2;
  3308. dev_info(&info->client->dev, "%s: %s(%d)\n", __func__,
  3309. buff, strnlen(buff, sizeof(buff)));
  3310. }
  3311. */
  3312. static ssize_t store_cmd(struct device *dev, struct device_attribute
  3313. *devattr, const char *buf, size_t count)
  3314. {
  3315. struct bt532_ts_info *info = dev_get_drvdata(dev);
  3316. struct i2c_client *client = info->client;
  3317. struct tsp_factory_info *finfo = info->factory_info;
  3318. char *cur, *start, *end;
  3319. char buff[TSP_CMD_STR_LEN] = {0};
  3320. int len, i;
  3321. struct tsp_cmd *tsp_cmd_ptr = NULL;
  3322. char delim = ',';
  3323. bool cmd_found = false;
  3324. int param_cnt = 0;
  3325. if (strlen(buf) >= TSP_CMD_STR_LEN) {
  3326. dev_err(&client->dev, "%s: cmd length is over(%s,%d)!!\n", __func__, buf, (int)strlen(buf));
  3327. return -EINVAL;
  3328. }
  3329. if (finfo->cmd_is_running == true) {
  3330. dev_err(&client->dev, "%s: other cmd is running\n", __func__);
  3331. goto err_out;
  3332. }
  3333. /* check lock */
  3334. mutex_lock(&finfo->cmd_lock);
  3335. finfo->cmd_is_running = true;
  3336. mutex_unlock(&finfo->cmd_lock);
  3337. finfo->cmd_state = RUNNING;
  3338. for (i = 0; i < ARRAY_SIZE(finfo->cmd_param); i++)
  3339. finfo->cmd_param[i] = 0;
  3340. len = (int)count;
  3341. if (*(buf + len - 1) == '\n')
  3342. len--;
  3343. memset(finfo->cmd, 0x00, ARRAY_SIZE(finfo->cmd));
  3344. memcpy(finfo->cmd, buf, len);
  3345. cur = strchr(buf, (int)delim);
  3346. if (cur)
  3347. memcpy(buff, buf, cur - buf);
  3348. else
  3349. memcpy(buff, buf, len);
  3350. /* find command */
  3351. list_for_each_entry(tsp_cmd_ptr, &finfo->cmd_list_head, list) {
  3352. if (!strcmp(buff, tsp_cmd_ptr->cmd_name)) {
  3353. cmd_found = true;
  3354. break;
  3355. }
  3356. }
  3357. /* set not_support_cmd */
  3358. if (!cmd_found) {
  3359. list_for_each_entry(tsp_cmd_ptr, &finfo->cmd_list_head, list) {
  3360. if (!strcmp("not_support_cmd", tsp_cmd_ptr->cmd_name))
  3361. break;
  3362. }
  3363. }
  3364. /* parsing parameters */
  3365. if (cur && cmd_found) {
  3366. cur++;
  3367. start = cur;
  3368. memset(buff, 0x00, ARRAY_SIZE(buff));
  3369. do {
  3370. if (*cur == delim || cur - buf == len) {
  3371. end = cur;
  3372. memcpy(buff, start, end - start);
  3373. *(buff + strlen(buff)) = '\0';
  3374. finfo->cmd_param[param_cnt] =
  3375. (int)simple_strtol(buff, NULL, 10);
  3376. start = cur + 1;
  3377. memset(buff, 0x00, ARRAY_SIZE(buff));
  3378. param_cnt++;
  3379. }
  3380. cur++;
  3381. } while ((cur - buf <= len) && (param_cnt < TSP_CMD_PARAM_NUM));
  3382. }
  3383. dev_info(&client->dev, "cmd = %s\n", tsp_cmd_ptr->cmd_name);
  3384. /* for (i = 0; i < param_cnt; i++)
  3385. dev_info(&client->dev, "cmd param %d= %d\n", i, finfo->cmd_param[i]);*/
  3386. tsp_cmd_ptr->cmd_func(info);
  3387. err_out:
  3388. return count;
  3389. }
  3390. static ssize_t show_cmd_status(struct device *dev,
  3391. struct device_attribute *devattr, char *buf)
  3392. {
  3393. struct bt532_ts_info *info = dev_get_drvdata(dev);
  3394. struct i2c_client *client = info->client;
  3395. struct tsp_factory_info *finfo = info->factory_info;
  3396. dev_info(&client->dev, "tsp cmd: status:%d\n", finfo->cmd_state);
  3397. if (finfo->cmd_state == WAITING)
  3398. snprintf(finfo->cmd_buff, sizeof(finfo->cmd_buff), "WAITING");
  3399. else if (finfo->cmd_state == RUNNING)
  3400. snprintf(finfo->cmd_buff, sizeof(finfo->cmd_buff), "RUNNING");
  3401. else if (finfo->cmd_state == OK)
  3402. snprintf(finfo->cmd_buff, sizeof(finfo->cmd_buff), "OK");
  3403. else if (finfo->cmd_state == FAIL)
  3404. snprintf(finfo->cmd_buff, sizeof(finfo->cmd_buff), "FAIL");
  3405. else if (finfo->cmd_state == NOT_APPLICABLE)
  3406. snprintf(finfo->cmd_buff, sizeof(finfo->cmd_buff), "NOT_APPLICABLE");
  3407. return snprintf(buf, sizeof(finfo->cmd_buff),
  3408. "%s\n", finfo->cmd_buff);
  3409. }
  3410. static ssize_t show_cmd_result(struct device *dev, struct device_attribute
  3411. *devattr, char *buf)
  3412. {
  3413. struct bt532_ts_info *info = dev_get_drvdata(dev);
  3414. struct i2c_client *client = info->client;
  3415. struct tsp_factory_info *finfo = info->factory_info;
  3416. dev_info(&client->dev, "tsp cmd: result: %s\n", finfo->cmd_result);
  3417. mutex_lock(&finfo->cmd_lock);
  3418. finfo->cmd_is_running = false;
  3419. mutex_unlock(&finfo->cmd_lock);
  3420. finfo->cmd_state = WAITING;
  3421. return snprintf(buf, sizeof(finfo->cmd_result),
  3422. "%s\n", finfo->cmd_result);
  3423. }
  3424. static DEVICE_ATTR(cmd, S_IWUSR | S_IWGRP, NULL, store_cmd);
  3425. static DEVICE_ATTR(cmd_status, S_IRUGO, show_cmd_status, NULL);
  3426. static DEVICE_ATTR(cmd_result, S_IRUGO, show_cmd_result, NULL);
  3427. static struct attribute *touchscreen_attributes[] = {
  3428. &dev_attr_cmd.attr,
  3429. &dev_attr_cmd_status.attr,
  3430. &dev_attr_cmd_result.attr,
  3431. NULL,
  3432. };
  3433. static struct attribute_group touchscreen_attr_group = {
  3434. .attrs = touchscreen_attributes,
  3435. };
  3436. #ifdef SUPPORTED_TOUCH_KEY
  3437. static ssize_t show_touchkey_threshold(struct device *dev,
  3438. struct device_attribute *attr, char *buf)
  3439. {
  3440. struct bt532_ts_info *info = dev_get_drvdata(dev);
  3441. struct i2c_client *client = info->client;
  3442. struct capa_info *cap = &(info->cap_info);
  3443. #ifdef NOT_SUPPORTED_TOUCH_DUMMY_KEY
  3444. dev_info(&client->dev, "%s: key threshold = %d\n", __func__,
  3445. cap->key_threshold);
  3446. return snprintf(buf, 41, "%d", cap->key_threshold);
  3447. #else
  3448. dev_info(&client->dev, "%s: key threshold = %d %d %d %d\n", __func__,
  3449. cap->dummy_threshold, cap->key_threshold, cap->key_threshold, cap->dummy_threshold);
  3450. return snprintf(buf, 41, "%d %d %d %d", cap->dummy_threshold,
  3451. cap->key_threshold, cap->key_threshold,
  3452. cap->dummy_threshold);
  3453. #endif
  3454. }
  3455. #if 0
  3456. static ssize_t enable_dummy_key(struct device *dev,
  3457. struct device_attribute *attr, char *buf, size_t count)
  3458. {
  3459. static char enable = '0';
  3460. struct bt532_ts_info *info = dev_get_drvdata(dev);
  3461. struct i2c_client *client = info->client;
  3462. if (!strcmp(buf, ""))
  3463. count = sprintf(buf, "%c", enable);
  3464. else {
  3465. if ((buf[0] - '0' <= 1) && count == 2)
  3466. enable = *buf;
  3467. else {
  3468. dev_err(&client->dev, "%s: Invalid parameter\n", __func__);
  3469. goto err_out;
  3470. }
  3471. }
  3472. dev_info(&client->dev, "%s: Extra button event %c\n", __func__, enable);
  3473. return count;
  3474. err_out:
  3475. return sprintf(buf, "NG");
  3476. return 0;
  3477. }
  3478. #endif
  3479. static ssize_t show_touchkey_sensitivity(struct device *dev,
  3480. struct device_attribute *attr, char *buf)
  3481. {
  3482. struct bt532_ts_info *info = dev_get_drvdata(dev);
  3483. struct i2c_client *client = info->client;
  3484. u16 val = 0;
  3485. int ret;
  3486. int i;
  3487. #ifdef NOT_SUPPORTED_TOUCH_DUMMY_KEY
  3488. if (!strcmp(attr->attr.name, "touchkey_recent"))
  3489. i = 0;
  3490. else if (!strcmp(attr->attr.name, "touchkey_back"))
  3491. i = 1;
  3492. else {
  3493. dev_err(&client->dev, "%s: Invalid attribute\n",__func__);
  3494. goto err_out;
  3495. }
  3496. #else
  3497. if (!strcmp(attr->attr.name, "touchkey_dummy_btn1"))
  3498. i = 0;
  3499. else if (!strcmp(attr->attr.name, "touchkey_recent"))
  3500. i = 1;
  3501. else if (!strcmp(attr->attr.name, "touchkey_back"))
  3502. i = 2;
  3503. else if (!strcmp(attr->attr.name, "touchkey_dummy_btn4"))
  3504. i = 3;
  3505. else if (!strcmp(attr->attr.name, "touchkey_dummy_btn5"))
  3506. i = 4;
  3507. else if (!strcmp(attr->attr.name, "touchkey_dummy_btn6"))
  3508. i = 5;
  3509. else {
  3510. dev_err(&client->dev, "%s: Invalid attribute\n", __func__);
  3511. goto err_out;
  3512. }
  3513. #endif
  3514. ret = read_data(client, BT532_BTN_WIDTH + i, (u8 *)&val, 2);
  3515. if (ret < 0) {
  3516. dev_err(&client->dev, "%s:Failed to read %d's key sensitivity\n",
  3517. __func__, i);
  3518. goto err_out;
  3519. }
  3520. dev_info(&client->dev, "%s: %d's key sensitivity = %d\n",
  3521. __func__, i, val);
  3522. return snprintf(buf, 6, "%d", val);
  3523. err_out:
  3524. return sprintf(buf, "NG");
  3525. }
  3526. static ssize_t show_back_key_raw_data(struct device *dev,
  3527. struct device_attribute *attr, char *buf)
  3528. {
  3529. return 0;
  3530. }
  3531. static ssize_t show_menu_key_raw_data(struct device *dev,
  3532. struct device_attribute *attr, char *buf)
  3533. {
  3534. return 0;
  3535. }
  3536. /*
  3537. static ssize_t show_back_key_idac_data(struct device *dev,
  3538. struct device_attribute *attr, char *buf)
  3539. {
  3540. return 0;
  3541. }
  3542. static ssize_t show_menu_key_idac_data(struct device *dev,
  3543. struct device_attribute *attr, char *buf)
  3544. {
  3545. return 0;
  3546. }
  3547. */
  3548. #if SUPPORTED_TOUCH_KEY_LED
  3549. static ssize_t touch_led_control(struct device *dev, struct device_attribute *attr, const char *buf, size_t size)
  3550. {
  3551. struct bt532_ts_info *info = dev_get_drvdata(dev);
  3552. u8 data;
  3553. sscanf(buf, "%hhu", &data);
  3554. printk("[TKEY] %s : %d _ %d\n",__func__,data,__LINE__);
  3555. if(data == 1)
  3556. gpio_direction_output(info->pdata->gpio_keyled, 1);
  3557. else
  3558. gpio_direction_output(info->pdata->gpio_keyled, 0);
  3559. return size;
  3560. }
  3561. #endif
  3562. static DEVICE_ATTR(touchkey_threshold, S_IRUGO, show_touchkey_threshold, NULL);
  3563. /*static DEVICE_ATTR(touch_sensitivity, S_IRUGO, back_key_state_show, NULL);*/
  3564. //static DEVICE_ATTR(extra_button_event, S_IWUSR | S_IWGRP | S_IRUGO, NULL, enable_dummy_key );
  3565. //static DEVICE_ATTR(touchkey_menu, S_IRUGO, show_touchkey_sensitivity, NULL);
  3566. static DEVICE_ATTR(touchkey_back, S_IRUGO, show_touchkey_sensitivity, NULL);
  3567. static DEVICE_ATTR(touchkey_recent, S_IRUGO, show_touchkey_sensitivity, NULL);
  3568. #ifndef NOT_SUPPORTED_TOUCH_DUMMY_KEY
  3569. static DEVICE_ATTR(touchkey_dummy_btn1, S_IRUGO,
  3570. show_touchkey_sensitivity, NULL);
  3571. static DEVICE_ATTR(touchkey_dummy_btn3, S_IRUGO,
  3572. show_touchkey_sensitivity, NULL);
  3573. static DEVICE_ATTR(touchkey_dummy_btn4, S_IRUGO,
  3574. show_touchkey_sensitivity, NULL);
  3575. static DEVICE_ATTR(touchkey_dummy_btn6, S_IRUGO,
  3576. show_touchkey_sensitivity, NULL);
  3577. #endif
  3578. /*static DEVICE_ATTR(autocal_stat, S_IRUGO, show_autocal_status, NULL);*/
  3579. static DEVICE_ATTR(touchkey_raw_back, S_IRUGO, show_back_key_raw_data, NULL);
  3580. static DEVICE_ATTR(touchkey_raw_menu, S_IRUGO, show_menu_key_raw_data, NULL);
  3581. /*static DEVICE_ATTR(touchkey_idac_back, S_IRUGO, show_back_key_idac_data, NULL);
  3582. static DEVICE_ATTR(touchkey_idac_menu, S_IRUGO, show_menu_key_idac_data, NULL);*/
  3583. #if SUPPORTED_TOUCH_KEY_LED
  3584. static DEVICE_ATTR(brightness, 0664, NULL, touch_led_control);
  3585. #endif
  3586. static struct attribute *touchkey_attributes[] = {
  3587. &dev_attr_touchkey_threshold.attr,
  3588. /*&dev_attr_touch_sensitivity.attr,*/
  3589. &dev_attr_touchkey_back.attr,
  3590. // &dev_attr_touchkey_menu.attr,
  3591. &dev_attr_touchkey_recent.attr,
  3592. //&dev_attr_autocal_stat.attr,
  3593. //&dev_attr_extra_button_event.attr,
  3594. &dev_attr_touchkey_raw_menu.attr,
  3595. &dev_attr_touchkey_raw_back.attr,
  3596. #ifndef NOT_SUPPORTED_TOUCH_DUMMY_KEY
  3597. &dev_attr_touchkey_dummy_btn1.attr,
  3598. &dev_attr_touchkey_dummy_btn3.attr,
  3599. &dev_attr_touchkey_dummy_btn4.attr,
  3600. &dev_attr_touchkey_dummy_btn6.attr,
  3601. #endif
  3602. //&dev_attr_touchkey_idac_back.attr,
  3603. //&dev_attr_touchkey_idac_menu.attr,
  3604. #if SUPPORTED_TOUCH_KEY_LED
  3605. &dev_attr_brightness.attr,
  3606. #endif
  3607. NULL,
  3608. };
  3609. static struct attribute_group touchkey_attr_group = {
  3610. .attrs = touchkey_attributes,
  3611. };
  3612. #endif
  3613. static int init_sec_factory(struct bt532_ts_info *info)
  3614. {
  3615. struct device *factory_ts_dev;
  3616. #ifdef SUPPORTED_TOUCH_KEY
  3617. struct device *factory_tk_dev;
  3618. #endif
  3619. struct tsp_factory_info *factory_info;
  3620. struct tsp_raw_data *raw_data;
  3621. int ret;
  3622. int i;
  3623. factory_info = kzalloc(sizeof(struct tsp_factory_info), GFP_KERNEL);
  3624. if (unlikely(!factory_info)) {
  3625. dev_err(&info->client->dev, "%s: Failed to allocate memory\n",
  3626. __func__);
  3627. ret = -ENOMEM;
  3628. goto err_alloc1;
  3629. }
  3630. raw_data = kzalloc(sizeof(struct tsp_raw_data), GFP_KERNEL);
  3631. if (unlikely(!raw_data)) {
  3632. dev_err(&info->client->dev, "%s: Failed to allocate memory\n",
  3633. __func__);
  3634. ret = -ENOMEM;
  3635. goto err_alloc2;
  3636. }
  3637. INIT_LIST_HEAD(&factory_info->cmd_list_head);
  3638. for (i = 0; i < ARRAY_SIZE(tsp_cmds); i++)
  3639. list_add_tail(&tsp_cmds[i].list, &factory_info->cmd_list_head);
  3640. factory_ts_dev = device_create(sec_class, NULL, 0, info, "tsp");
  3641. if (unlikely(!factory_ts_dev)) {
  3642. dev_err(&info->client->dev, "Failed to create factory dev\n");
  3643. ret = -ENODEV;
  3644. goto err_create_device;
  3645. }
  3646. #ifdef SUPPORTED_TOUCH_KEY
  3647. factory_tk_dev = device_create(sec_class, NULL, 0, info, "sec_touchkey");
  3648. if (IS_ERR(factory_tk_dev)) {
  3649. dev_err(&info->client->dev, "Failed to create factory dev\n");
  3650. ret = -ENODEV;
  3651. goto err_create_device;
  3652. }
  3653. #endif
  3654. ret = sysfs_create_group(&factory_ts_dev->kobj, &touchscreen_attr_group);
  3655. if (unlikely(ret)) {
  3656. dev_err(&info->client->dev, "Failed to create touchscreen sysfs group\n");
  3657. goto err_create_sysfs;
  3658. }
  3659. ret = sysfs_create_link(&factory_ts_dev->kobj, &info->input_dev->dev.kobj, "input");
  3660. if (ret < 0) {
  3661. dev_err(&info->client->dev, "Failed to create input symbolic link\n");
  3662. }
  3663. #ifdef SUPPORTED_TOUCH_KEY
  3664. ret = sysfs_create_group(&factory_tk_dev->kobj, &touchkey_attr_group);
  3665. if (unlikely(ret)) {
  3666. dev_err(&info->client->dev, "Failed to create touchkey sysfs group\n");
  3667. goto err_create_sysfs;
  3668. }
  3669. #endif
  3670. mutex_init(&factory_info->cmd_lock);
  3671. factory_info->cmd_is_running = false;
  3672. info->factory_info = factory_info;
  3673. info->raw_data = raw_data;
  3674. return ret;
  3675. err_create_sysfs:
  3676. err_create_device:
  3677. kfree(raw_data);
  3678. err_alloc2:
  3679. kfree(factory_info);
  3680. err_alloc1:
  3681. return ret;
  3682. }
  3683. #endif
  3684. static int ts_misc_fops_open(struct inode *inode, struct file *filp)
  3685. {
  3686. return 0;
  3687. }
  3688. static int ts_misc_fops_close(struct inode *inode, struct file *filp)
  3689. {
  3690. return 0;
  3691. }
  3692. static long ts_misc_fops_ioctl(struct file *filp,
  3693. unsigned int cmd, unsigned long arg)
  3694. {
  3695. void __user *argp = (void __user *)arg;
  3696. struct raw_ioctl raw_ioctl;
  3697. u8 *u8Data;
  3698. int ret = 0;
  3699. size_t sz = 0;
  3700. u16 version;
  3701. u16 mode;
  3702. struct reg_ioctl reg_ioctl;
  3703. u16 val;
  3704. int nval = 0;
  3705. if (misc_info == NULL)
  3706. {
  3707. zinitix_debug_msg("misc device NULL?\n");
  3708. return -1;
  3709. }
  3710. switch (cmd) {
  3711. case TOUCH_IOCTL_GET_DEBUGMSG_STATE:
  3712. ret = m_ts_debug_mode;
  3713. if (copy_to_user(argp, &ret, sizeof(ret)))
  3714. return -1;
  3715. break;
  3716. case TOUCH_IOCTL_SET_DEBUGMSG_STATE:
  3717. if (copy_from_user(&nval, argp, 4)) {
  3718. pr_info("[zinitix_touch] error : copy_from_user\n");
  3719. return -1;
  3720. }
  3721. if (nval)
  3722. pr_info("[zinitix_touch] on debug mode (%d)\n",
  3723. nval);
  3724. else
  3725. pr_info("[zinitix_touch] off debug mode (%d)\n",
  3726. nval);
  3727. m_ts_debug_mode = nval;
  3728. break;
  3729. case TOUCH_IOCTL_GET_CHIP_REVISION:
  3730. ret = misc_info->cap_info.ic_revision;
  3731. if (copy_to_user(argp, &ret, sizeof(ret)))
  3732. return -1;
  3733. break;
  3734. case TOUCH_IOCTL_GET_FW_VERSION:
  3735. ret = misc_info->cap_info.fw_version;
  3736. if (copy_to_user(argp, &ret, sizeof(ret)))
  3737. return -1;
  3738. break;
  3739. case TOUCH_IOCTL_GET_REG_DATA_VERSION:
  3740. ret = misc_info->cap_info.reg_data_version;
  3741. if (copy_to_user(argp, &ret, sizeof(ret)))
  3742. return -1;
  3743. break;
  3744. case TOUCH_IOCTL_VARIFY_UPGRADE_SIZE:
  3745. if (copy_from_user(&sz, argp, sizeof(size_t)))
  3746. return -1;
  3747. printk(KERN_INFO "[zinitix_touch]: firmware size = %d\r\n", sz);
  3748. if (misc_info->cap_info.ic_fw_size != sz) {
  3749. pr_info("[zinitix_touch]: firmware size error\r\n");
  3750. return -1;
  3751. }
  3752. break;
  3753. case TOUCH_IOCTL_VARIFY_UPGRADE_DATA:
  3754. if (copy_from_user(m_firmware_data,
  3755. argp, misc_info->cap_info.ic_fw_size))
  3756. return -1;
  3757. version = (u16) (m_firmware_data[52] | (m_firmware_data[53]<<8));
  3758. pr_info("[zinitix_touch]: firmware version = %x\r\n", version);
  3759. if (copy_to_user(argp, &version, sizeof(version)))
  3760. return -1;
  3761. break;
  3762. case TOUCH_IOCTL_START_UPGRADE:
  3763. return ts_upgrade_sequence((u8 *)m_firmware_data);
  3764. case TOUCH_IOCTL_GET_X_RESOLUTION:
  3765. ret = misc_info->pdata->x_resolution;
  3766. if (copy_to_user(argp, &ret, sizeof(ret)))
  3767. return -1;
  3768. break;
  3769. case TOUCH_IOCTL_GET_Y_RESOLUTION:
  3770. ret = misc_info->pdata->y_resolution;
  3771. if (copy_to_user(argp, &ret, sizeof(ret)))
  3772. return -1;
  3773. break;
  3774. case TOUCH_IOCTL_GET_X_NODE_NUM:
  3775. ret = misc_info->cap_info.x_node_num;
  3776. if (copy_to_user(argp, &ret, sizeof(ret)))
  3777. return -1;
  3778. break;
  3779. case TOUCH_IOCTL_GET_Y_NODE_NUM:
  3780. ret = misc_info->cap_info.y_node_num;
  3781. if (copy_to_user(argp, &ret, sizeof(ret)))
  3782. return -1;
  3783. break;
  3784. case TOUCH_IOCTL_GET_TOTAL_NODE_NUM:
  3785. ret = misc_info->cap_info.total_node_num;
  3786. if (copy_to_user(argp, &ret, sizeof(ret)))
  3787. return -1;
  3788. break;
  3789. case TOUCH_IOCTL_HW_CALIBRAION:
  3790. ret = -1;
  3791. disable_irq(misc_info->irq);
  3792. down(&misc_info->work_lock);
  3793. if (misc_info->work_state != NOTHING) {
  3794. pr_info("[zinitix_touch]: other process occupied.. (%d)\r\n",
  3795. misc_info->work_state);
  3796. up(&misc_info->work_lock);
  3797. return -1;
  3798. }
  3799. misc_info->work_state = HW_CALIBRAION;
  3800. mdelay(100);
  3801. /* h/w calibration */
  3802. if (ts_hw_calibration(misc_info) == true)
  3803. ret = 0;
  3804. mode = misc_info->touch_mode;
  3805. if (write_reg(misc_info->client,
  3806. BT532_TOUCH_MODE, mode) != I2C_SUCCESS) {
  3807. pr_err("[zinitix_touch]: failed to set touch mode %d.\n",
  3808. mode);
  3809. goto fail_hw_cal;
  3810. }
  3811. if (write_cmd(misc_info->client,
  3812. BT532_SWRESET_CMD) != I2C_SUCCESS)
  3813. goto fail_hw_cal;
  3814. enable_irq(misc_info->irq);
  3815. misc_info->work_state = NOTHING;
  3816. up(&misc_info->work_lock);
  3817. return ret;
  3818. fail_hw_cal:
  3819. enable_irq(misc_info->irq);
  3820. misc_info->work_state = NOTHING;
  3821. up(&misc_info->work_lock);
  3822. return -1;
  3823. case TOUCH_IOCTL_SET_RAW_DATA_MODE:
  3824. if (misc_info == NULL) {
  3825. zinitix_debug_msg("misc device NULL?\n");
  3826. return -1;
  3827. }
  3828. if (copy_from_user(&nval, argp, 4)) {
  3829. pr_info("[zinitix_touch] error : copy_from_user\r\n");
  3830. misc_info->work_state = NOTHING;
  3831. return -1;
  3832. }
  3833. ts_set_touchmode((u16)nval);
  3834. return 0;
  3835. case TOUCH_IOCTL_GET_REG:
  3836. if (misc_info == NULL) {
  3837. zinitix_debug_msg("misc device NULL?\n");
  3838. return -1;
  3839. }
  3840. down(&misc_info->work_lock);
  3841. if (misc_info->work_state != NOTHING) {
  3842. pr_info("[zinitix_touch]:other process occupied.. (%d)\n",
  3843. misc_info->work_state);
  3844. up(&misc_info->work_lock);
  3845. return -1;
  3846. }
  3847. misc_info->work_state = SET_MODE;
  3848. if (copy_from_user(&reg_ioctl,
  3849. argp, sizeof(struct reg_ioctl))) {
  3850. misc_info->work_state = NOTHING;
  3851. up(&misc_info->work_lock);
  3852. pr_info("[zinitix_touch] error : copy_from_user\n");
  3853. return -1;
  3854. }
  3855. if (read_data(misc_info->client,
  3856. reg_ioctl.addr, (u8 *)&val, 2) < 0)
  3857. ret = -1;
  3858. nval = (int)val;
  3859. if (copy_to_user(reg_ioctl.val, (u8 *)&nval, 4)) {
  3860. misc_info->work_state = NOTHING;
  3861. up(&misc_info->work_lock);
  3862. pr_info("[zinitix_touch] error : copy_to_user\n");
  3863. return -1;
  3864. }
  3865. zinitix_debug_msg("read : reg addr = 0x%x, val = 0x%x\n",
  3866. reg_ioctl.addr, nval);
  3867. misc_info->work_state = NOTHING;
  3868. up(&misc_info->work_lock);
  3869. return ret;
  3870. case TOUCH_IOCTL_SET_REG:
  3871. down(&misc_info->work_lock);
  3872. if (misc_info->work_state != NOTHING) {
  3873. pr_info("[zinitix_touch]: other process occupied.. (%d)\n",
  3874. misc_info->work_state);
  3875. up(&misc_info->work_lock);
  3876. return -1;
  3877. }
  3878. misc_info->work_state = SET_MODE;
  3879. if (copy_from_user(&reg_ioctl,
  3880. argp, sizeof(struct reg_ioctl))) {
  3881. misc_info->work_state = NOTHING;
  3882. up(&misc_info->work_lock);
  3883. pr_info("[zinitix_touch] error : copy_from_user\n");
  3884. return -1;
  3885. }
  3886. if (copy_from_user(&val, reg_ioctl.val, 4)) {
  3887. misc_info->work_state = NOTHING;
  3888. up(&misc_info->work_lock);
  3889. pr_info("[zinitix_touch] error : copy_from_user\n");
  3890. return -1;
  3891. }
  3892. if (write_reg(misc_info->client,
  3893. reg_ioctl.addr, val) != I2C_SUCCESS)
  3894. ret = -1;
  3895. zinitix_debug_msg("write : reg addr = 0x%x, val = 0x%x\r\n",
  3896. reg_ioctl.addr, val);
  3897. misc_info->work_state = NOTHING;
  3898. up(&misc_info->work_lock);
  3899. return ret;
  3900. case TOUCH_IOCTL_DONOT_TOUCH_EVENT:
  3901. if (misc_info == NULL) {
  3902. zinitix_debug_msg("misc device NULL?\n");
  3903. return -1;
  3904. }
  3905. down(&misc_info->work_lock);
  3906. if (misc_info->work_state != NOTHING) {
  3907. pr_info("[zinitix_touch]: other process occupied.. (%d)\r\n",
  3908. misc_info->work_state);
  3909. up(&misc_info->work_lock);
  3910. return -1;
  3911. }
  3912. misc_info->work_state = SET_MODE;
  3913. if (write_reg(misc_info->client,
  3914. BT532_INT_ENABLE_FLAG, 0) != I2C_SUCCESS)
  3915. ret = -1;
  3916. zinitix_debug_msg("write : reg addr = 0x%x, val = 0x0\r\n",
  3917. BT532_INT_ENABLE_FLAG);
  3918. misc_info->work_state = NOTHING;
  3919. up(&misc_info->work_lock);
  3920. return ret;
  3921. case TOUCH_IOCTL_SEND_SAVE_STATUS:
  3922. if (misc_info == NULL) {
  3923. zinitix_debug_msg("misc device NULL?\n");
  3924. return -1;
  3925. }
  3926. down(&misc_info->work_lock);
  3927. if (misc_info->work_state != NOTHING) {
  3928. pr_info("[zinitix_touch]: other process occupied.." \
  3929. "(%d)\r\n", misc_info->work_state);
  3930. up(&misc_info->work_lock);
  3931. return -1;
  3932. }
  3933. misc_info->work_state = SET_MODE;
  3934. ret = 0;
  3935. write_reg(misc_info->client, 0xc003, 0x0001);
  3936. write_reg(misc_info->client, 0xc104, 0x0001);
  3937. if (write_cmd(misc_info->client,
  3938. BT532_SAVE_STATUS_CMD) != I2C_SUCCESS)
  3939. ret = -1;
  3940. mdelay(1000); /* for fusing eeprom */
  3941. write_reg(misc_info->client, 0xc003, 0x0000);
  3942. write_reg(misc_info->client, 0xc104, 0x0000);
  3943. misc_info->work_state = NOTHING;
  3944. up(&misc_info->work_lock);
  3945. return ret;
  3946. case TOUCH_IOCTL_GET_RAW_DATA:
  3947. if (misc_info == NULL) {
  3948. zinitix_debug_msg("misc device NULL?\n");
  3949. return -1;
  3950. }
  3951. if (misc_info->touch_mode == TOUCH_POINT_MODE)
  3952. return -1;
  3953. down(&misc_info->raw_data_lock);
  3954. if (misc_info->update == 0) {
  3955. up(&misc_info->raw_data_lock);
  3956. return -2;
  3957. }
  3958. if (copy_from_user(&raw_ioctl,
  3959. argp, sizeof(struct raw_ioctl))) {
  3960. up(&misc_info->raw_data_lock);
  3961. pr_info("[zinitix_touch] error : copy_from_user\r\n");
  3962. return -1;
  3963. }
  3964. misc_info->update = 0;
  3965. u8Data = (u8 *)&misc_info->cur_data[0];
  3966. if (raw_ioctl.sz > MAX_TRAW_DATA_SZ*2)
  3967. raw_ioctl.sz = MAX_TRAW_DATA_SZ*2;
  3968. if (copy_to_user(raw_ioctl.buf, (u8 *)u8Data,
  3969. raw_ioctl.sz)) {
  3970. up(&misc_info->raw_data_lock);
  3971. return -1;
  3972. }
  3973. up(&misc_info->raw_data_lock);
  3974. return 0;
  3975. default:
  3976. break;
  3977. }
  3978. return 0;
  3979. }
  3980. #ifdef CONFIG_OF
  3981. static const struct of_device_id zinitix_match_table[] = {
  3982. { .compatible = "zinitix,bt532_ts_device",},
  3983. {},
  3984. };
  3985. static int zinitix_init_gpio(struct bt532_ts_platform_data *pdata)
  3986. {
  3987. int ret = 0;
  3988. ret = gpio_request(pdata->gpio_int, "zinitix_tsp_irq");
  3989. if(ret) {
  3990. pr_err("[TSP]%s: unable to request zinitix_tsp_irq [%d]\n",
  3991. __func__, pdata->gpio_int);
  3992. return ret;
  3993. }
  3994. gpio_tlmm_config(GPIO_CFG(pdata->gpio_int, 0,
  3995. GPIO_CFG_INPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), 1);
  3996. #if !defined(CONFIG_SEC_MEGA23G_COMMON) && !defined(CONFIG_SEC_MEGA2LTE_COMMON) && !defined(CONFIG_SEC_VASTALTE_CHN_CMMCC_DUOS_PROJECT)
  3997. ret = gpio_request(pdata->tsp_vendor1, "zinitix_tsp_vendor1");
  3998. if (ret) {
  3999. pr_err("[TSP]%s: unable to request zinitix_tsp_vendor1 [%d]\n",
  4000. __func__, pdata->tsp_vendor1);
  4001. return ret;
  4002. }
  4003. ret = gpio_request(pdata->tsp_vendor2, "zinitix_tsp_vendor2");
  4004. if (ret) {
  4005. pr_err("[TSP]%s: unable to request zinitix_tsp_vendor2 [%d]\n",
  4006. __func__, pdata->tsp_vendor2);
  4007. return ret;
  4008. }
  4009. #endif
  4010. if (pdata->tsp_supply_type == TSP_LDO_SUPPLY)
  4011. {
  4012. ret = gpio_request(pdata->tsp_en_gpio, "zinitix_tsp_en_gpio");
  4013. if(ret) {
  4014. pr_err("[TSP]%s: unable to request zinitix_tsp_en_gpio [%d]\n",
  4015. __func__, pdata->tsp_en_gpio);
  4016. return ret;
  4017. }
  4018. gpio_tlmm_config(GPIO_CFG(pdata->tsp_en_gpio, 0,
  4019. GPIO_CFG_OUTPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), GPIO_CFG_ENABLE);
  4020. }
  4021. #if SUPPORTED_TOUCH_KEY_LED
  4022. if (pdata->gpio_keyled >= 0) {
  4023. ret = gpio_request(pdata->gpio_keyled, "key_led_gpio");
  4024. if (ret < 0) {
  4025. pr_err("%s: gpio_request failed: %d\n", __func__, ret);
  4026. return ret;
  4027. }
  4028. }
  4029. #endif
  4030. return ret;
  4031. }
  4032. #endif
  4033. static int bt532_ts_probe_dt(struct device_node *np,
  4034. struct device *dev,
  4035. struct bt532_ts_platform_data *pdata)
  4036. {
  4037. #if SUPPORTED_TOUCH_KEY_LED
  4038. int keyled_n = -1;
  4039. int size_p;
  4040. #endif
  4041. int ret = 0;
  4042. u32 temp;
  4043. ret = of_property_read_u32(np, "zinitix,x_resolution", &temp);
  4044. if (ret) {
  4045. dev_err(dev, "Unable to read controller version\n");
  4046. return ret;
  4047. } else
  4048. pdata->x_resolution = (u16) temp;
  4049. ret = of_property_read_u32(np, "zinitix,y_resolution", &temp);
  4050. if (ret) {
  4051. dev_err(dev, "Unable to read controller version\n");
  4052. return ret;
  4053. } else
  4054. pdata->y_resolution = (u16) temp;
  4055. ret = of_property_read_u32(np, "zinitix,page_size", &temp);
  4056. if (ret) {
  4057. dev_err(dev, "Unable to read controller version\n");
  4058. return ret;
  4059. } else
  4060. pdata->page_size = (u16) temp;
  4061. ret = of_property_read_u32(np, "zinitix,orientation", &temp);
  4062. if (ret) {
  4063. dev_err(dev, "Unable to read controller version\n");
  4064. return ret;
  4065. } else
  4066. pdata->orientation = (u8) temp;
  4067. pdata->tsp_vendor1 = of_get_named_gpio(np, "zinitix,vendor1", 0);
  4068. pdata->tsp_vendor2 = of_get_named_gpio(np, "zinitix,vendor2", 0);
  4069. #if SUPPORTED_TOUCH_KEY_LED
  4070. if (of_find_property(np, "keyled_gpio", &size_p)) {
  4071. keyled_n = of_get_named_gpio(np, "keyled_gpio", 0);
  4072. if (keyled_n < 0) {
  4073. pr_err("%s: of_get_named_gpio failed: keyled_gpio %d\n", __func__,
  4074. keyled_n);
  4075. return -EINVAL;
  4076. }
  4077. }
  4078. pdata->gpio_keyled = keyled_n;
  4079. #endif
  4080. pdata->gpio_int = of_get_named_gpio(np, "zinitix,irq-gpio", 0);
  4081. if (pdata->gpio_int < 0) {
  4082. pr_err("%s: of_get_named_gpio failed: tsp_gpio %d\n", __func__,
  4083. pdata->gpio_int);
  4084. return -EINVAL;
  4085. }
  4086. ret = of_property_read_u32(np, "zinitix,tsp_vdd_supply_type",
  4087. &pdata->tsp_supply_type);
  4088. if (ret < 0) {
  4089. pr_err("%s: failed to read property tsp_vdd_supply_type\n",
  4090. __func__);
  4091. return ret;
  4092. }
  4093. ret = of_property_read_string(np, "zinitix,pname",
  4094. &pdata->pname);
  4095. if (ret < 0) {
  4096. pr_err("%s: failed to read property config_ver\n",
  4097. __func__);
  4098. return ret;
  4099. }
  4100. if (pdata->tsp_supply_type == TSP_LDO_SUPPLY) {
  4101. pdata->tsp_en_gpio = of_get_named_gpio(np, "zinitix,vdd_en-gpio", 0);
  4102. if (pdata->tsp_en_gpio < 0) {
  4103. pr_err("%s: of_get_named_gpio failed: %d\n", __func__,
  4104. pdata->tsp_en_gpio);
  4105. return -EINVAL;
  4106. }
  4107. }
  4108. return 0;
  4109. }
  4110. static int bt532_ts_probe(struct i2c_client *client,
  4111. const struct i2c_device_id *i2c_id)
  4112. {
  4113. struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
  4114. struct bt532_ts_platform_data *pdata = NULL;
  4115. struct bt532_ts_info *info;
  4116. struct input_dev *input_dev;
  4117. int ret = 0;
  4118. int i;
  4119. struct device_node *np = client->dev.of_node;
  4120. zinitix_printk("[TSP]: %s\n", __func__);
  4121. if (client->dev.of_node) {
  4122. if (!pdata) {
  4123. pdata = devm_kzalloc(&client->dev,
  4124. sizeof(*pdata), GFP_KERNEL);
  4125. if (!pdata)
  4126. return -ENOMEM;
  4127. }
  4128. ret = bt532_ts_probe_dt(np, &client->dev, pdata);
  4129. if (ret){
  4130. dev_err(&client->dev, "Error parsing dt %d\n", ret);
  4131. goto err_no_platform_data;
  4132. }
  4133. ret = zinitix_init_gpio(pdata);
  4134. if(ret < 0)
  4135. goto err_gpio_request;
  4136. } else if (!pdata) {
  4137. dev_err(&client->dev, "%s: no platform data defined\n",
  4138. __func__);
  4139. return -EINVAL;
  4140. }
  4141. if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
  4142. dev_err(&client->dev, "Not compatible i2c function\n");
  4143. ret = -EIO;
  4144. goto err_no_platform_data;
  4145. }
  4146. #if 0
  4147. if (pdata->tsp_supply_type == TSP_LDO_SUPPLY) {
  4148. ret = gpio_request(pdata->tsp_en_gpio, "tsp_en_gpio");
  4149. if (ret < 0) {
  4150. pr_err("%s: gpio_request failed: %d\n", __func__, ret);
  4151. goto err_gpio_request;
  4152. }
  4153. }
  4154. #endif
  4155. info = kzalloc(sizeof(struct bt532_ts_info), GFP_KERNEL);
  4156. if (!info) {
  4157. dev_err(&client->dev, "%s: Failed to allocate memory\n", __func__);
  4158. ret = -ENOMEM;
  4159. goto err_mem_alloc;
  4160. }
  4161. i2c_set_clientdata(client, info);
  4162. info->client = client;
  4163. info->pdata = pdata;
  4164. info->device_enabled = 1;
  4165. input_dev = input_allocate_device();
  4166. if (!input_dev) {
  4167. dev_err(&client->dev, "Failed to allocate input device\n");
  4168. ret = -ENOMEM;
  4169. goto err_alloc;
  4170. }
  4171. info->input_dev = input_dev;
  4172. info->work_state = PROBE;
  4173. info->vddo_vreg = regulator_get(&info->client->dev,"vddo");
  4174. if (IS_ERR(info->vddo_vreg)){
  4175. info->vddo_vreg = NULL;
  4176. printk(KERN_INFO "info->vddo_vreg error\n");
  4177. ret = -EPERM;
  4178. goto err_power_sequence;
  4179. }
  4180. if (pdata->tsp_supply_type == TSP_REGULATOR_SUPPLY)
  4181. {
  4182. info->vdd_en = regulator_get(&info->client->dev,"vdd_en");
  4183. if (IS_ERR(info->vdd_en)){
  4184. info->vdd_en = NULL;
  4185. printk(KERN_INFO "info->vdd_en error\n");
  4186. ret = -EPERM;
  4187. goto err_power_sequence;
  4188. }
  4189. }
  4190. /* power on */
  4191. if (bt532_power_control(info, POWER_ON_SEQUENCE) == false) {
  4192. ret = -EPERM;
  4193. goto err_power_sequence;
  4194. }
  4195. /* To Do */
  4196. /* FW version read from tsp */
  4197. memset(&info->reported_touch_info,
  4198. 0x0, sizeof(struct point_info));
  4199. /* init touch mode */
  4200. info->touch_mode = TOUCH_POINT_MODE;
  4201. misc_info = info;
  4202. bt532_firmware_check(pdata);
  4203. if (init_touch(info) == false) {
  4204. ret = -EPERM;
  4205. goto err_input_register_device;
  4206. }
  4207. for (i = 0; i < MAX_SUPPORTED_BUTTON_NUM; i++)
  4208. info->button[i] = ICON_BUTTON_UNCHANGE;
  4209. snprintf(info->phys, sizeof(info->phys),
  4210. "%s/input0", dev_name(&client->dev));
  4211. input_dev->name = "sec_touchscreen";
  4212. input_dev->id.bustype = BUS_I2C;
  4213. /* input_dev->id.vendor = 0x0001; */
  4214. input_dev->phys = info->phys;
  4215. /* input_dev->id.product = 0x0002; */
  4216. /* input_dev->id.version = 0x0100; */
  4217. input_dev->dev.parent = &client->dev;
  4218. set_bit(EV_SYN, info->input_dev->evbit);
  4219. set_bit(EV_KEY, info->input_dev->evbit);
  4220. set_bit(EV_ABS, info->input_dev->evbit);
  4221. #if SUPPORTED_TOUCH_KEY_LED
  4222. set_bit(EV_LED, info->input_dev->evbit);
  4223. set_bit(LED_MISC, info->input_dev->ledbit);
  4224. #endif
  4225. set_bit(INPUT_PROP_DIRECT, info->input_dev->propbit);
  4226. for (i = 0; i < MAX_SUPPORTED_BUTTON_NUM; i++)
  4227. set_bit(BUTTON_MAPPING_KEY[i], info->input_dev->keybit);
  4228. if (pdata->orientation & TOUCH_XY_SWAP) {
  4229. input_set_abs_params(info->input_dev, ABS_MT_POSITION_Y,
  4230. info->cap_info.MinX,
  4231. info->cap_info.MaxX + ABS_PT_OFFSET,
  4232. 0, 0);
  4233. input_set_abs_params(info->input_dev, ABS_MT_POSITION_X,
  4234. info->cap_info.MinY,
  4235. info->cap_info.MaxY + ABS_PT_OFFSET,
  4236. 0, 0);
  4237. } else {
  4238. input_set_abs_params(info->input_dev, ABS_MT_POSITION_X,
  4239. info->cap_info.MinX,
  4240. info->cap_info.MaxX + ABS_PT_OFFSET,
  4241. 0, 0);
  4242. input_set_abs_params(info->input_dev, ABS_MT_POSITION_Y,
  4243. info->cap_info.MinY,
  4244. info->cap_info.MaxY + ABS_PT_OFFSET,
  4245. 0, 0);
  4246. }
  4247. input_set_abs_params(info->input_dev, ABS_MT_TOUCH_MAJOR,
  4248. 0, 255, 0, 0);
  4249. input_set_abs_params(info->input_dev, ABS_MT_WIDTH_MAJOR,
  4250. 0, 255, 0, 0);
  4251. #if (TOUCH_POINT_MODE == 2)
  4252. input_set_abs_params(info->input_dev, ABS_MT_TOUCH_MINOR,
  4253. 0, 255, 0, 0);
  4254. /* input_set_abs_params(info->input_dev, ABS_MT_WIDTH_MINOR,
  4255. 0, 255, 0, 0); */
  4256. /* input_set_abs_params(info->input_dev, ABS_MT_ORIENTATION,
  4257. -128, 127, 0, 0); */
  4258. input_set_abs_params(info->input_dev, ABS_MT_PALM,
  4259. 0, 1, 0, 0);
  4260. #endif
  4261. info->input_dev->open = bt532_input_open;
  4262. info->input_dev->close = bt532_input_close;
  4263. set_bit(MT_TOOL_FINGER, info->input_dev->keybit);
  4264. input_mt_init_slots(info->input_dev, info->cap_info.multi_fingers);
  4265. zinitix_debug_msg("register %s input device \r\n",
  4266. info->input_dev->name);
  4267. input_set_drvdata(info->input_dev, info);
  4268. ret = input_register_device(info->input_dev);
  4269. if (ret) {
  4270. pr_err("unable to register %s input device\r\n",
  4271. info->input_dev->name);
  4272. goto err_input_register_device;
  4273. }
  4274. info->work_state = NOTHING;
  4275. sema_init(&info->work_lock, 1);
  4276. #if ESD_TIMER_INTERVAL
  4277. spin_lock_init(&info->lock);
  4278. INIT_WORK(&info->tmr_work, ts_tmr_work);
  4279. esd_tmr_workqueue =
  4280. create_singlethread_workqueue("esd_tmr_workqueue");
  4281. if (!esd_tmr_workqueue) {
  4282. dev_err(&client->dev, "Failed to create esd tmr work queue\n");
  4283. ret = -EPERM;
  4284. goto err_input_register_device;
  4285. }
  4286. esd_timer_init(info);
  4287. esd_timer_start(CHECK_ESD_TIMER, info);
  4288. #if defined(TSP_VERBOSE_DEBUG)
  4289. dev_info(&client->dev, "Started esd timer\n");
  4290. #endif
  4291. #endif
  4292. #if 0
  4293. info->irq = irq_of_parse_and_map(client->dev.of_node, 0);
  4294. if (!info->irq) {
  4295. dev_err(&client->dev, "Failed to retrieve IRQ from device tree.\n");
  4296. ret = -ENODEV;
  4297. goto err_irq_of_parse;
  4298. }
  4299. #endif
  4300. #ifdef TSP_BOOSTER
  4301. mutex_init(&info->dvfs_lock);
  4302. info->touch_pressed_num = 0;
  4303. info->dvfs_lock_status = false;
  4304. info->boost_level = DVFS_STAGE_DUAL;
  4305. INIT_DELAYED_WORK(&info->work_dvfs_off, set_dvfs_off);
  4306. INIT_DELAYED_WORK(&info->work_dvfs_chg, change_dvfs_lock);
  4307. #endif
  4308. /* configure irq */
  4309. info->irq = gpio_to_irq(pdata->gpio_int);
  4310. if (info->irq < 0){
  4311. dev_err(&client->dev, "Invalid GPIO_TOUCH_IRQ\n");
  4312. ret = -ENODEV;
  4313. goto err_irq_of_parse;;
  4314. }
  4315. pdata->tsp_irq = info->irq;
  4316. ret = request_threaded_irq(info->irq, NULL, bt532_touch_work,
  4317. IRQF_TRIGGER_FALLING | IRQF_ONESHOT , BT532_TS_DEVICE, info);
  4318. if (ret) {
  4319. printk(KERN_ERR "unable to register irq.(%s)\r\n",
  4320. info->input_dev->name);
  4321. goto err_request_irq;
  4322. }
  4323. dev_info(&client->dev, "zinitix touch probe.\r\n");
  4324. #if defined(CONFIG_PM_RUNTIME)
  4325. //pm_runtime_enable(&client->dev);
  4326. #endif
  4327. sema_init(&info->raw_data_lock, 1);
  4328. ret = misc_register(&touch_misc_device);
  4329. if (ret) {
  4330. dev_err(&client->dev, "Failed to register touch misc device\n");
  4331. goto err_misc_register;
  4332. }
  4333. #ifdef SEC_FACTORY_TEST
  4334. ret = init_sec_factory(info);
  4335. if (ret) {
  4336. dev_err(&client->dev, "Failed to init sec factory device\n");
  4337. goto err_kthread_create_failed;
  4338. }
  4339. #endif
  4340. //tsp_charger_status_cb = bt532_charger_status_cb;
  4341. return 0;
  4342. #ifdef SEC_FACTORY_TEST
  4343. err_kthread_create_failed:
  4344. kfree(info->factory_info);
  4345. kfree(info->raw_data);
  4346. #endif
  4347. err_misc_register:
  4348. free_irq(info->irq, info);
  4349. err_irq_of_parse:
  4350. err_request_irq:
  4351. input_unregister_device(info->input_dev);
  4352. err_input_register_device:
  4353. input_free_device(info->input_dev);
  4354. err_power_sequence:
  4355. err_alloc:
  4356. kfree(info);
  4357. err_mem_alloc:
  4358. gpio_free(pdata->tsp_en_gpio);
  4359. err_gpio_request:
  4360. #if SUPPORTED_TOUCH_KEY_LED
  4361. if (pdata->gpio_keyled >= 0)
  4362. gpio_free(pdata->gpio_keyled);
  4363. #endif
  4364. err_no_platform_data:
  4365. if (IS_ENABLED(CONFIG_OF))
  4366. devm_kfree(&client->dev, (void *)pdata);
  4367. dev_info(&client->dev, "Failed to probe\n");
  4368. return ret;
  4369. }
  4370. static int bt532_ts_remove(struct i2c_client *client)
  4371. {
  4372. struct bt532_ts_info *info = i2c_get_clientdata(client);
  4373. struct bt532_ts_platform_data *pdata = info->pdata;
  4374. disable_irq(info->irq);
  4375. down(&info->work_lock);
  4376. info->work_state = REMOVE;
  4377. #ifdef SEC_FACTORY_TEST
  4378. kfree(info->factory_info);
  4379. kfree(info->raw_data);
  4380. #endif
  4381. #if ESD_TIMER_INTERVAL
  4382. flush_work(&info->tmr_work);
  4383. write_reg(info->client, BT532_PERIODICAL_INTERRUPT_INTERVAL, 0);
  4384. esd_timer_stop(info);
  4385. #if defined(TSP_VERBOSE_DEBUG)
  4386. dev_info(&client->dev, "Stopped esd timer\n");
  4387. #endif
  4388. destroy_workqueue(esd_tmr_workqueue);
  4389. #endif
  4390. if (info->irq)
  4391. free_irq(info->irq, info);
  4392. misc_deregister(&touch_misc_device);
  4393. if (gpio_is_valid(pdata->gpio_int) != 0)
  4394. gpio_free(pdata->gpio_int);
  4395. #if SUPPORTED_TOUCH_KEY_LED
  4396. if (gpio_is_valid(pdata->gpio_keyled) != 0)
  4397. gpio_free(pdata->gpio_keyled);
  4398. #endif
  4399. if (pdata->tsp_supply_type == TSP_LDO_SUPPLY)
  4400. if (gpio_is_valid(pdata->tsp_en_gpio) != 0)
  4401. gpio_free(pdata->tsp_en_gpio);
  4402. input_unregister_device(info->input_dev);
  4403. input_free_device(info->input_dev);
  4404. up(&info->work_lock);
  4405. kfree(info);
  4406. return 0;
  4407. }
  4408. void bt532_ts_shutdown(struct i2c_client *client)
  4409. {
  4410. struct bt532_ts_info *info = i2c_get_clientdata(client);
  4411. dev_info(&client->dev, "%s++\n", __func__);
  4412. disable_irq(info->irq);
  4413. down(&info->work_lock);
  4414. #if ESD_TIMER_INTERVAL
  4415. flush_work(&info->tmr_work);
  4416. esd_timer_stop(info);
  4417. #endif
  4418. up(&info->work_lock);
  4419. bt532_power_control(info, POWER_OFF);
  4420. dev_info(&client->dev, "%s--\n", __func__);
  4421. }
  4422. static struct i2c_device_id bt532_idtable[] = {
  4423. {BT532_TS_DEVICE, 0},
  4424. { }
  4425. };
  4426. /*#if defined(CONFIG_PM)
  4427. static const struct dev_pm_ops bt532_ts_pm_ops = {
  4428. .suspend = bt532_ts_suspend,
  4429. .resume = bt532_ts_resume,
  4430. };
  4431. #endif*/
  4432. static struct i2c_driver bt532_ts_driver = {
  4433. .probe = bt532_ts_probe,
  4434. .remove = bt532_ts_remove,
  4435. .shutdown = bt532_ts_shutdown,
  4436. .id_table = bt532_idtable,
  4437. .driver = {
  4438. .owner = THIS_MODULE,
  4439. .name = BT532_TS_DEVICE,
  4440. /*#if defined(CONFIG_PM)
  4441. .pm = &bt532_ts_pm_ops,
  4442. #endif*/
  4443. .of_match_table = zinitix_match_table,
  4444. },
  4445. };
  4446. static int __init bt532_ts_init(void)
  4447. {
  4448. pr_debug("[TSP]: %s\n", __func__);
  4449. zinitix_printk("[TSP]: %s\n", __func__);
  4450. #ifdef CONFIG_SAMSUNG_LPM_MODE
  4451. if (poweroff_charging) {
  4452. pr_notice("%s : LPM Charging Mode!!\n", __func__);
  4453. return 0;
  4454. }
  4455. #endif
  4456. return i2c_add_driver(&bt532_ts_driver);
  4457. }
  4458. static void __exit bt532_ts_exit(void)
  4459. {
  4460. i2c_del_driver(&bt532_ts_driver);
  4461. }
  4462. module_init(bt532_ts_init);
  4463. module_exit(bt532_ts_exit);
  4464. MODULE_DESCRIPTION("touch-screen device driver using i2c interface");
  4465. MODULE_AUTHOR("<mika.kim@samsung.com>");
  4466. MODULE_LICENSE("GPL");