zinitix_touch.c 123 KB

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