dsi.c 87 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786
  1. /*
  2. * linux/drivers/video/omap2/dss/dsi.c
  3. *
  4. * Copyright (C) 2009 Nokia Corporation
  5. * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License version 2 as published by
  9. * the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along with
  17. * this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #define DSS_SUBSYS_NAME "DSI"
  20. #include <linux/kernel.h>
  21. #include <linux/io.h>
  22. #include <linux/clk.h>
  23. #include <linux/device.h>
  24. #include <linux/err.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/delay.h>
  27. #include <linux/mutex.h>
  28. #include <linux/semaphore.h>
  29. #include <linux/seq_file.h>
  30. #include <linux/platform_device.h>
  31. #include <linux/regulator/consumer.h>
  32. #include <linux/wait.h>
  33. #include <linux/workqueue.h>
  34. #include <plat/display.h>
  35. #include <plat/clock.h>
  36. #include "dss.h"
  37. #include "dss_features.h"
  38. /*#define VERBOSE_IRQ*/
  39. #define DSI_CATCH_MISSING_TE
  40. struct dsi_reg { u16 idx; };
  41. #define DSI_REG(idx) ((const struct dsi_reg) { idx })
  42. #define DSI_SZ_REGS SZ_1K
  43. /* DSI Protocol Engine */
  44. #define DSI_REVISION DSI_REG(0x0000)
  45. #define DSI_SYSCONFIG DSI_REG(0x0010)
  46. #define DSI_SYSSTATUS DSI_REG(0x0014)
  47. #define DSI_IRQSTATUS DSI_REG(0x0018)
  48. #define DSI_IRQENABLE DSI_REG(0x001C)
  49. #define DSI_CTRL DSI_REG(0x0040)
  50. #define DSI_COMPLEXIO_CFG1 DSI_REG(0x0048)
  51. #define DSI_COMPLEXIO_IRQ_STATUS DSI_REG(0x004C)
  52. #define DSI_COMPLEXIO_IRQ_ENABLE DSI_REG(0x0050)
  53. #define DSI_CLK_CTRL DSI_REG(0x0054)
  54. #define DSI_TIMING1 DSI_REG(0x0058)
  55. #define DSI_TIMING2 DSI_REG(0x005C)
  56. #define DSI_VM_TIMING1 DSI_REG(0x0060)
  57. #define DSI_VM_TIMING2 DSI_REG(0x0064)
  58. #define DSI_VM_TIMING3 DSI_REG(0x0068)
  59. #define DSI_CLK_TIMING DSI_REG(0x006C)
  60. #define DSI_TX_FIFO_VC_SIZE DSI_REG(0x0070)
  61. #define DSI_RX_FIFO_VC_SIZE DSI_REG(0x0074)
  62. #define DSI_COMPLEXIO_CFG2 DSI_REG(0x0078)
  63. #define DSI_RX_FIFO_VC_FULLNESS DSI_REG(0x007C)
  64. #define DSI_VM_TIMING4 DSI_REG(0x0080)
  65. #define DSI_TX_FIFO_VC_EMPTINESS DSI_REG(0x0084)
  66. #define DSI_VM_TIMING5 DSI_REG(0x0088)
  67. #define DSI_VM_TIMING6 DSI_REG(0x008C)
  68. #define DSI_VM_TIMING7 DSI_REG(0x0090)
  69. #define DSI_STOPCLK_TIMING DSI_REG(0x0094)
  70. #define DSI_VC_CTRL(n) DSI_REG(0x0100 + (n * 0x20))
  71. #define DSI_VC_TE(n) DSI_REG(0x0104 + (n * 0x20))
  72. #define DSI_VC_LONG_PACKET_HEADER(n) DSI_REG(0x0108 + (n * 0x20))
  73. #define DSI_VC_LONG_PACKET_PAYLOAD(n) DSI_REG(0x010C + (n * 0x20))
  74. #define DSI_VC_SHORT_PACKET_HEADER(n) DSI_REG(0x0110 + (n * 0x20))
  75. #define DSI_VC_IRQSTATUS(n) DSI_REG(0x0118 + (n * 0x20))
  76. #define DSI_VC_IRQENABLE(n) DSI_REG(0x011C + (n * 0x20))
  77. /* DSIPHY_SCP */
  78. #define DSI_DSIPHY_CFG0 DSI_REG(0x200 + 0x0000)
  79. #define DSI_DSIPHY_CFG1 DSI_REG(0x200 + 0x0004)
  80. #define DSI_DSIPHY_CFG2 DSI_REG(0x200 + 0x0008)
  81. #define DSI_DSIPHY_CFG5 DSI_REG(0x200 + 0x0014)
  82. /* DSI_PLL_CTRL_SCP */
  83. #define DSI_PLL_CONTROL DSI_REG(0x300 + 0x0000)
  84. #define DSI_PLL_STATUS DSI_REG(0x300 + 0x0004)
  85. #define DSI_PLL_GO DSI_REG(0x300 + 0x0008)
  86. #define DSI_PLL_CONFIGURATION1 DSI_REG(0x300 + 0x000C)
  87. #define DSI_PLL_CONFIGURATION2 DSI_REG(0x300 + 0x0010)
  88. #define REG_GET(idx, start, end) \
  89. FLD_GET(dsi_read_reg(idx), start, end)
  90. #define REG_FLD_MOD(idx, val, start, end) \
  91. dsi_write_reg(idx, FLD_MOD(dsi_read_reg(idx), val, start, end))
  92. /* Global interrupts */
  93. #define DSI_IRQ_VC0 (1 << 0)
  94. #define DSI_IRQ_VC1 (1 << 1)
  95. #define DSI_IRQ_VC2 (1 << 2)
  96. #define DSI_IRQ_VC3 (1 << 3)
  97. #define DSI_IRQ_WAKEUP (1 << 4)
  98. #define DSI_IRQ_RESYNC (1 << 5)
  99. #define DSI_IRQ_PLL_LOCK (1 << 7)
  100. #define DSI_IRQ_PLL_UNLOCK (1 << 8)
  101. #define DSI_IRQ_PLL_RECALL (1 << 9)
  102. #define DSI_IRQ_COMPLEXIO_ERR (1 << 10)
  103. #define DSI_IRQ_HS_TX_TIMEOUT (1 << 14)
  104. #define DSI_IRQ_LP_RX_TIMEOUT (1 << 15)
  105. #define DSI_IRQ_TE_TRIGGER (1 << 16)
  106. #define DSI_IRQ_ACK_TRIGGER (1 << 17)
  107. #define DSI_IRQ_SYNC_LOST (1 << 18)
  108. #define DSI_IRQ_LDO_POWER_GOOD (1 << 19)
  109. #define DSI_IRQ_TA_TIMEOUT (1 << 20)
  110. #define DSI_IRQ_ERROR_MASK \
  111. (DSI_IRQ_HS_TX_TIMEOUT | DSI_IRQ_LP_RX_TIMEOUT | DSI_IRQ_SYNC_LOST | \
  112. DSI_IRQ_TA_TIMEOUT)
  113. #define DSI_IRQ_CHANNEL_MASK 0xf
  114. /* Virtual channel interrupts */
  115. #define DSI_VC_IRQ_CS (1 << 0)
  116. #define DSI_VC_IRQ_ECC_CORR (1 << 1)
  117. #define DSI_VC_IRQ_PACKET_SENT (1 << 2)
  118. #define DSI_VC_IRQ_FIFO_TX_OVF (1 << 3)
  119. #define DSI_VC_IRQ_FIFO_RX_OVF (1 << 4)
  120. #define DSI_VC_IRQ_BTA (1 << 5)
  121. #define DSI_VC_IRQ_ECC_NO_CORR (1 << 6)
  122. #define DSI_VC_IRQ_FIFO_TX_UDF (1 << 7)
  123. #define DSI_VC_IRQ_PP_BUSY_CHANGE (1 << 8)
  124. #define DSI_VC_IRQ_ERROR_MASK \
  125. (DSI_VC_IRQ_CS | DSI_VC_IRQ_ECC_CORR | DSI_VC_IRQ_FIFO_TX_OVF | \
  126. DSI_VC_IRQ_FIFO_RX_OVF | DSI_VC_IRQ_ECC_NO_CORR | \
  127. DSI_VC_IRQ_FIFO_TX_UDF)
  128. /* ComplexIO interrupts */
  129. #define DSI_CIO_IRQ_ERRSYNCESC1 (1 << 0)
  130. #define DSI_CIO_IRQ_ERRSYNCESC2 (1 << 1)
  131. #define DSI_CIO_IRQ_ERRSYNCESC3 (1 << 2)
  132. #define DSI_CIO_IRQ_ERRESC1 (1 << 5)
  133. #define DSI_CIO_IRQ_ERRESC2 (1 << 6)
  134. #define DSI_CIO_IRQ_ERRESC3 (1 << 7)
  135. #define DSI_CIO_IRQ_ERRCONTROL1 (1 << 10)
  136. #define DSI_CIO_IRQ_ERRCONTROL2 (1 << 11)
  137. #define DSI_CIO_IRQ_ERRCONTROL3 (1 << 12)
  138. #define DSI_CIO_IRQ_STATEULPS1 (1 << 15)
  139. #define DSI_CIO_IRQ_STATEULPS2 (1 << 16)
  140. #define DSI_CIO_IRQ_STATEULPS3 (1 << 17)
  141. #define DSI_CIO_IRQ_ERRCONTENTIONLP0_1 (1 << 20)
  142. #define DSI_CIO_IRQ_ERRCONTENTIONLP1_1 (1 << 21)
  143. #define DSI_CIO_IRQ_ERRCONTENTIONLP0_2 (1 << 22)
  144. #define DSI_CIO_IRQ_ERRCONTENTIONLP1_2 (1 << 23)
  145. #define DSI_CIO_IRQ_ERRCONTENTIONLP0_3 (1 << 24)
  146. #define DSI_CIO_IRQ_ERRCONTENTIONLP1_3 (1 << 25)
  147. #define DSI_CIO_IRQ_ULPSACTIVENOT_ALL0 (1 << 30)
  148. #define DSI_CIO_IRQ_ULPSACTIVENOT_ALL1 (1 << 31)
  149. #define DSI_CIO_IRQ_ERROR_MASK \
  150. (DSI_CIO_IRQ_ERRSYNCESC1 | DSI_CIO_IRQ_ERRSYNCESC2 | \
  151. DSI_CIO_IRQ_ERRSYNCESC3 | DSI_CIO_IRQ_ERRESC1 | DSI_CIO_IRQ_ERRESC2 | \
  152. DSI_CIO_IRQ_ERRESC3 | DSI_CIO_IRQ_ERRCONTROL1 | \
  153. DSI_CIO_IRQ_ERRCONTROL2 | DSI_CIO_IRQ_ERRCONTROL3 | \
  154. DSI_CIO_IRQ_ERRCONTENTIONLP0_1 | DSI_CIO_IRQ_ERRCONTENTIONLP1_1 | \
  155. DSI_CIO_IRQ_ERRCONTENTIONLP0_2 | DSI_CIO_IRQ_ERRCONTENTIONLP1_2 | \
  156. DSI_CIO_IRQ_ERRCONTENTIONLP0_3 | DSI_CIO_IRQ_ERRCONTENTIONLP1_3)
  157. #define DSI_DT_DCS_SHORT_WRITE_0 0x05
  158. #define DSI_DT_DCS_SHORT_WRITE_1 0x15
  159. #define DSI_DT_DCS_READ 0x06
  160. #define DSI_DT_SET_MAX_RET_PKG_SIZE 0x37
  161. #define DSI_DT_NULL_PACKET 0x09
  162. #define DSI_DT_DCS_LONG_WRITE 0x39
  163. #define DSI_DT_RX_ACK_WITH_ERR 0x02
  164. #define DSI_DT_RX_DCS_LONG_READ 0x1c
  165. #define DSI_DT_RX_SHORT_READ_1 0x21
  166. #define DSI_DT_RX_SHORT_READ_2 0x22
  167. typedef void (*omap_dsi_isr_t) (void *arg, u32 mask);
  168. #define DSI_MAX_NR_ISRS 2
  169. struct dsi_isr_data {
  170. omap_dsi_isr_t isr;
  171. void *arg;
  172. u32 mask;
  173. };
  174. enum fifo_size {
  175. DSI_FIFO_SIZE_0 = 0,
  176. DSI_FIFO_SIZE_32 = 1,
  177. DSI_FIFO_SIZE_64 = 2,
  178. DSI_FIFO_SIZE_96 = 3,
  179. DSI_FIFO_SIZE_128 = 4,
  180. };
  181. enum dsi_vc_mode {
  182. DSI_VC_MODE_L4 = 0,
  183. DSI_VC_MODE_VP,
  184. };
  185. struct dsi_update_region {
  186. u16 x, y, w, h;
  187. struct omap_dss_device *device;
  188. };
  189. struct dsi_irq_stats {
  190. unsigned long last_reset;
  191. unsigned irq_count;
  192. unsigned dsi_irqs[32];
  193. unsigned vc_irqs[4][32];
  194. unsigned cio_irqs[32];
  195. };
  196. struct dsi_isr_tables {
  197. struct dsi_isr_data isr_table[DSI_MAX_NR_ISRS];
  198. struct dsi_isr_data isr_table_vc[4][DSI_MAX_NR_ISRS];
  199. struct dsi_isr_data isr_table_cio[DSI_MAX_NR_ISRS];
  200. };
  201. static struct
  202. {
  203. struct platform_device *pdev;
  204. void __iomem *base;
  205. int irq;
  206. struct dsi_clock_info current_cinfo;
  207. struct regulator *vdds_dsi_reg;
  208. struct {
  209. enum dsi_vc_mode mode;
  210. struct omap_dss_device *dssdev;
  211. enum fifo_size fifo_size;
  212. int vc_id;
  213. } vc[4];
  214. struct mutex lock;
  215. struct semaphore bus_lock;
  216. unsigned pll_locked;
  217. spinlock_t irq_lock;
  218. struct dsi_isr_tables isr_tables;
  219. /* space for a copy used by the interrupt handler */
  220. struct dsi_isr_tables isr_tables_copy;
  221. int update_channel;
  222. struct dsi_update_region update_region;
  223. bool te_enabled;
  224. struct workqueue_struct *workqueue;
  225. void (*framedone_callback)(int, void *);
  226. void *framedone_data;
  227. struct delayed_work framedone_timeout_work;
  228. #ifdef DSI_CATCH_MISSING_TE
  229. struct timer_list te_timer;
  230. #endif
  231. unsigned long cache_req_pck;
  232. unsigned long cache_clk_freq;
  233. struct dsi_clock_info cache_cinfo;
  234. u32 errors;
  235. spinlock_t errors_lock;
  236. #ifdef DEBUG
  237. ktime_t perf_setup_time;
  238. ktime_t perf_start_time;
  239. #endif
  240. int debug_read;
  241. int debug_write;
  242. #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
  243. spinlock_t irq_stats_lock;
  244. struct dsi_irq_stats irq_stats;
  245. #endif
  246. /* DSI PLL Parameter Ranges */
  247. unsigned long regm_max, regn_max;
  248. unsigned long regm_dispc_max, regm_dsi_max;
  249. unsigned long fint_min, fint_max;
  250. unsigned long lpdiv_max;
  251. } dsi;
  252. #ifdef DEBUG
  253. static unsigned int dsi_perf;
  254. module_param_named(dsi_perf, dsi_perf, bool, 0644);
  255. #endif
  256. static inline void dsi_write_reg(const struct dsi_reg idx, u32 val)
  257. {
  258. __raw_writel(val, dsi.base + idx.idx);
  259. }
  260. static inline u32 dsi_read_reg(const struct dsi_reg idx)
  261. {
  262. return __raw_readl(dsi.base + idx.idx);
  263. }
  264. void dsi_save_context(void)
  265. {
  266. }
  267. void dsi_restore_context(void)
  268. {
  269. }
  270. void dsi_bus_lock(void)
  271. {
  272. down(&dsi.bus_lock);
  273. }
  274. EXPORT_SYMBOL(dsi_bus_lock);
  275. void dsi_bus_unlock(void)
  276. {
  277. up(&dsi.bus_lock);
  278. }
  279. EXPORT_SYMBOL(dsi_bus_unlock);
  280. static bool dsi_bus_is_locked(void)
  281. {
  282. return dsi.bus_lock.count == 0;
  283. }
  284. static void dsi_completion_handler(void *data, u32 mask)
  285. {
  286. complete((struct completion *)data);
  287. }
  288. static inline int wait_for_bit_change(const struct dsi_reg idx, int bitnum,
  289. int value)
  290. {
  291. int t = 100000;
  292. while (REG_GET(idx, bitnum, bitnum) != value) {
  293. if (--t == 0)
  294. return !value;
  295. }
  296. return value;
  297. }
  298. #ifdef DEBUG
  299. static void dsi_perf_mark_setup(void)
  300. {
  301. dsi.perf_setup_time = ktime_get();
  302. }
  303. static void dsi_perf_mark_start(void)
  304. {
  305. dsi.perf_start_time = ktime_get();
  306. }
  307. static void dsi_perf_show(const char *name)
  308. {
  309. ktime_t t, setup_time, trans_time;
  310. u32 total_bytes;
  311. u32 setup_us, trans_us, total_us;
  312. if (!dsi_perf)
  313. return;
  314. t = ktime_get();
  315. setup_time = ktime_sub(dsi.perf_start_time, dsi.perf_setup_time);
  316. setup_us = (u32)ktime_to_us(setup_time);
  317. if (setup_us == 0)
  318. setup_us = 1;
  319. trans_time = ktime_sub(t, dsi.perf_start_time);
  320. trans_us = (u32)ktime_to_us(trans_time);
  321. if (trans_us == 0)
  322. trans_us = 1;
  323. total_us = setup_us + trans_us;
  324. total_bytes = dsi.update_region.w *
  325. dsi.update_region.h *
  326. dsi.update_region.device->ctrl.pixel_size / 8;
  327. printk(KERN_INFO "DSI(%s): %u us + %u us = %u us (%uHz), "
  328. "%u bytes, %u kbytes/sec\n",
  329. name,
  330. setup_us,
  331. trans_us,
  332. total_us,
  333. 1000*1000 / total_us,
  334. total_bytes,
  335. total_bytes * 1000 / total_us);
  336. }
  337. #else
  338. #define dsi_perf_mark_setup()
  339. #define dsi_perf_mark_start()
  340. #define dsi_perf_show(x)
  341. #endif
  342. static void print_irq_status(u32 status)
  343. {
  344. if (status == 0)
  345. return;
  346. #ifndef VERBOSE_IRQ
  347. if ((status & ~DSI_IRQ_CHANNEL_MASK) == 0)
  348. return;
  349. #endif
  350. printk(KERN_DEBUG "DSI IRQ: 0x%x: ", status);
  351. #define PIS(x) \
  352. if (status & DSI_IRQ_##x) \
  353. printk(#x " ");
  354. #ifdef VERBOSE_IRQ
  355. PIS(VC0);
  356. PIS(VC1);
  357. PIS(VC2);
  358. PIS(VC3);
  359. #endif
  360. PIS(WAKEUP);
  361. PIS(RESYNC);
  362. PIS(PLL_LOCK);
  363. PIS(PLL_UNLOCK);
  364. PIS(PLL_RECALL);
  365. PIS(COMPLEXIO_ERR);
  366. PIS(HS_TX_TIMEOUT);
  367. PIS(LP_RX_TIMEOUT);
  368. PIS(TE_TRIGGER);
  369. PIS(ACK_TRIGGER);
  370. PIS(SYNC_LOST);
  371. PIS(LDO_POWER_GOOD);
  372. PIS(TA_TIMEOUT);
  373. #undef PIS
  374. printk("\n");
  375. }
  376. static void print_irq_status_vc(int channel, u32 status)
  377. {
  378. if (status == 0)
  379. return;
  380. #ifndef VERBOSE_IRQ
  381. if ((status & ~DSI_VC_IRQ_PACKET_SENT) == 0)
  382. return;
  383. #endif
  384. printk(KERN_DEBUG "DSI VC(%d) IRQ 0x%x: ", channel, status);
  385. #define PIS(x) \
  386. if (status & DSI_VC_IRQ_##x) \
  387. printk(#x " ");
  388. PIS(CS);
  389. PIS(ECC_CORR);
  390. #ifdef VERBOSE_IRQ
  391. PIS(PACKET_SENT);
  392. #endif
  393. PIS(FIFO_TX_OVF);
  394. PIS(FIFO_RX_OVF);
  395. PIS(BTA);
  396. PIS(ECC_NO_CORR);
  397. PIS(FIFO_TX_UDF);
  398. PIS(PP_BUSY_CHANGE);
  399. #undef PIS
  400. printk("\n");
  401. }
  402. static void print_irq_status_cio(u32 status)
  403. {
  404. if (status == 0)
  405. return;
  406. printk(KERN_DEBUG "DSI CIO IRQ 0x%x: ", status);
  407. #define PIS(x) \
  408. if (status & DSI_CIO_IRQ_##x) \
  409. printk(#x " ");
  410. PIS(ERRSYNCESC1);
  411. PIS(ERRSYNCESC2);
  412. PIS(ERRSYNCESC3);
  413. PIS(ERRESC1);
  414. PIS(ERRESC2);
  415. PIS(ERRESC3);
  416. PIS(ERRCONTROL1);
  417. PIS(ERRCONTROL2);
  418. PIS(ERRCONTROL3);
  419. PIS(STATEULPS1);
  420. PIS(STATEULPS2);
  421. PIS(STATEULPS3);
  422. PIS(ERRCONTENTIONLP0_1);
  423. PIS(ERRCONTENTIONLP1_1);
  424. PIS(ERRCONTENTIONLP0_2);
  425. PIS(ERRCONTENTIONLP1_2);
  426. PIS(ERRCONTENTIONLP0_3);
  427. PIS(ERRCONTENTIONLP1_3);
  428. PIS(ULPSACTIVENOT_ALL0);
  429. PIS(ULPSACTIVENOT_ALL1);
  430. #undef PIS
  431. printk("\n");
  432. }
  433. #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
  434. static void dsi_collect_irq_stats(u32 irqstatus, u32 *vcstatus, u32 ciostatus)
  435. {
  436. int i;
  437. spin_lock(&dsi.irq_stats_lock);
  438. dsi.irq_stats.irq_count++;
  439. dss_collect_irq_stats(irqstatus, dsi.irq_stats.dsi_irqs);
  440. for (i = 0; i < 4; ++i)
  441. dss_collect_irq_stats(vcstatus[i], dsi.irq_stats.vc_irqs[i]);
  442. dss_collect_irq_stats(ciostatus, dsi.irq_stats.cio_irqs);
  443. spin_unlock(&dsi.irq_stats_lock);
  444. }
  445. #else
  446. #define dsi_collect_irq_stats(irqstatus, vcstatus, ciostatus)
  447. #endif
  448. static int debug_irq;
  449. static void dsi_handle_irq_errors(u32 irqstatus, u32 *vcstatus, u32 ciostatus)
  450. {
  451. int i;
  452. if (irqstatus & DSI_IRQ_ERROR_MASK) {
  453. DSSERR("DSI error, irqstatus %x\n", irqstatus);
  454. print_irq_status(irqstatus);
  455. spin_lock(&dsi.errors_lock);
  456. dsi.errors |= irqstatus & DSI_IRQ_ERROR_MASK;
  457. spin_unlock(&dsi.errors_lock);
  458. } else if (debug_irq) {
  459. print_irq_status(irqstatus);
  460. }
  461. for (i = 0; i < 4; ++i) {
  462. if (vcstatus[i] & DSI_VC_IRQ_ERROR_MASK) {
  463. DSSERR("DSI VC(%d) error, vc irqstatus %x\n",
  464. i, vcstatus[i]);
  465. print_irq_status_vc(i, vcstatus[i]);
  466. } else if (debug_irq) {
  467. print_irq_status_vc(i, vcstatus[i]);
  468. }
  469. }
  470. if (ciostatus & DSI_CIO_IRQ_ERROR_MASK) {
  471. DSSERR("DSI CIO error, cio irqstatus %x\n", ciostatus);
  472. print_irq_status_cio(ciostatus);
  473. } else if (debug_irq) {
  474. print_irq_status_cio(ciostatus);
  475. }
  476. }
  477. static void dsi_call_isrs(struct dsi_isr_data *isr_array,
  478. unsigned isr_array_size, u32 irqstatus)
  479. {
  480. struct dsi_isr_data *isr_data;
  481. int i;
  482. for (i = 0; i < isr_array_size; i++) {
  483. isr_data = &isr_array[i];
  484. if (isr_data->isr && isr_data->mask & irqstatus)
  485. isr_data->isr(isr_data->arg, irqstatus);
  486. }
  487. }
  488. static void dsi_handle_isrs(struct dsi_isr_tables *isr_tables,
  489. u32 irqstatus, u32 *vcstatus, u32 ciostatus)
  490. {
  491. int i;
  492. dsi_call_isrs(isr_tables->isr_table,
  493. ARRAY_SIZE(isr_tables->isr_table),
  494. irqstatus);
  495. for (i = 0; i < 4; ++i) {
  496. if (vcstatus[i] == 0)
  497. continue;
  498. dsi_call_isrs(isr_tables->isr_table_vc[i],
  499. ARRAY_SIZE(isr_tables->isr_table_vc[i]),
  500. vcstatus[i]);
  501. }
  502. if (ciostatus != 0)
  503. dsi_call_isrs(isr_tables->isr_table_cio,
  504. ARRAY_SIZE(isr_tables->isr_table_cio),
  505. ciostatus);
  506. }
  507. static irqreturn_t omap_dsi_irq_handler(int irq, void *arg)
  508. {
  509. u32 irqstatus, vcstatus[4], ciostatus;
  510. int i;
  511. spin_lock(&dsi.irq_lock);
  512. irqstatus = dsi_read_reg(DSI_IRQSTATUS);
  513. /* IRQ is not for us */
  514. if (!irqstatus) {
  515. spin_unlock(&dsi.irq_lock);
  516. return IRQ_NONE;
  517. }
  518. dsi_write_reg(DSI_IRQSTATUS, irqstatus & ~DSI_IRQ_CHANNEL_MASK);
  519. /* flush posted write */
  520. dsi_read_reg(DSI_IRQSTATUS);
  521. for (i = 0; i < 4; ++i) {
  522. if ((irqstatus & (1 << i)) == 0) {
  523. vcstatus[i] = 0;
  524. continue;
  525. }
  526. vcstatus[i] = dsi_read_reg(DSI_VC_IRQSTATUS(i));
  527. dsi_write_reg(DSI_VC_IRQSTATUS(i), vcstatus[i]);
  528. /* flush posted write */
  529. dsi_read_reg(DSI_VC_IRQSTATUS(i));
  530. }
  531. if (irqstatus & DSI_IRQ_COMPLEXIO_ERR) {
  532. ciostatus = dsi_read_reg(DSI_COMPLEXIO_IRQ_STATUS);
  533. dsi_write_reg(DSI_COMPLEXIO_IRQ_STATUS, ciostatus);
  534. /* flush posted write */
  535. dsi_read_reg(DSI_COMPLEXIO_IRQ_STATUS);
  536. } else {
  537. ciostatus = 0;
  538. }
  539. #ifdef DSI_CATCH_MISSING_TE
  540. if (irqstatus & DSI_IRQ_TE_TRIGGER)
  541. del_timer(&dsi.te_timer);
  542. #endif
  543. /* make a copy and unlock, so that isrs can unregister
  544. * themselves */
  545. memcpy(&dsi.isr_tables_copy, &dsi.isr_tables, sizeof(dsi.isr_tables));
  546. spin_unlock(&dsi.irq_lock);
  547. dsi_handle_isrs(&dsi.isr_tables_copy, irqstatus, vcstatus, ciostatus);
  548. dsi_handle_irq_errors(irqstatus, vcstatus, ciostatus);
  549. dsi_collect_irq_stats(irqstatus, vcstatus, ciostatus);
  550. return IRQ_HANDLED;
  551. }
  552. /* dsi.irq_lock has to be locked by the caller */
  553. static void _omap_dsi_configure_irqs(struct dsi_isr_data *isr_array,
  554. unsigned isr_array_size, u32 default_mask,
  555. const struct dsi_reg enable_reg,
  556. const struct dsi_reg status_reg)
  557. {
  558. struct dsi_isr_data *isr_data;
  559. u32 mask;
  560. u32 old_mask;
  561. int i;
  562. mask = default_mask;
  563. for (i = 0; i < isr_array_size; i++) {
  564. isr_data = &isr_array[i];
  565. if (isr_data->isr == NULL)
  566. continue;
  567. mask |= isr_data->mask;
  568. }
  569. old_mask = dsi_read_reg(enable_reg);
  570. /* clear the irqstatus for newly enabled irqs */
  571. dsi_write_reg(status_reg, (mask ^ old_mask) & mask);
  572. dsi_write_reg(enable_reg, mask);
  573. /* flush posted writes */
  574. dsi_read_reg(enable_reg);
  575. dsi_read_reg(status_reg);
  576. }
  577. /* dsi.irq_lock has to be locked by the caller */
  578. static void _omap_dsi_set_irqs(void)
  579. {
  580. u32 mask = DSI_IRQ_ERROR_MASK;
  581. #ifdef DSI_CATCH_MISSING_TE
  582. mask |= DSI_IRQ_TE_TRIGGER;
  583. #endif
  584. _omap_dsi_configure_irqs(dsi.isr_tables.isr_table,
  585. ARRAY_SIZE(dsi.isr_tables.isr_table), mask,
  586. DSI_IRQENABLE, DSI_IRQSTATUS);
  587. }
  588. /* dsi.irq_lock has to be locked by the caller */
  589. static void _omap_dsi_set_irqs_vc(int vc)
  590. {
  591. _omap_dsi_configure_irqs(dsi.isr_tables.isr_table_vc[vc],
  592. ARRAY_SIZE(dsi.isr_tables.isr_table_vc[vc]),
  593. DSI_VC_IRQ_ERROR_MASK,
  594. DSI_VC_IRQENABLE(vc), DSI_VC_IRQSTATUS(vc));
  595. }
  596. /* dsi.irq_lock has to be locked by the caller */
  597. static void _omap_dsi_set_irqs_cio(void)
  598. {
  599. _omap_dsi_configure_irqs(dsi.isr_tables.isr_table_cio,
  600. ARRAY_SIZE(dsi.isr_tables.isr_table_cio),
  601. DSI_CIO_IRQ_ERROR_MASK,
  602. DSI_COMPLEXIO_IRQ_ENABLE, DSI_COMPLEXIO_IRQ_STATUS);
  603. }
  604. static void _dsi_initialize_irq(void)
  605. {
  606. unsigned long flags;
  607. int vc;
  608. spin_lock_irqsave(&dsi.irq_lock, flags);
  609. memset(&dsi.isr_tables, 0, sizeof(dsi.isr_tables));
  610. _omap_dsi_set_irqs();
  611. for (vc = 0; vc < 4; ++vc)
  612. _omap_dsi_set_irqs_vc(vc);
  613. _omap_dsi_set_irqs_cio();
  614. spin_unlock_irqrestore(&dsi.irq_lock, flags);
  615. }
  616. static int _dsi_register_isr(omap_dsi_isr_t isr, void *arg, u32 mask,
  617. struct dsi_isr_data *isr_array, unsigned isr_array_size)
  618. {
  619. struct dsi_isr_data *isr_data;
  620. int free_idx;
  621. int i;
  622. BUG_ON(isr == NULL);
  623. /* check for duplicate entry and find a free slot */
  624. free_idx = -1;
  625. for (i = 0; i < isr_array_size; i++) {
  626. isr_data = &isr_array[i];
  627. if (isr_data->isr == isr && isr_data->arg == arg &&
  628. isr_data->mask == mask) {
  629. return -EINVAL;
  630. }
  631. if (isr_data->isr == NULL && free_idx == -1)
  632. free_idx = i;
  633. }
  634. if (free_idx == -1)
  635. return -EBUSY;
  636. isr_data = &isr_array[free_idx];
  637. isr_data->isr = isr;
  638. isr_data->arg = arg;
  639. isr_data->mask = mask;
  640. return 0;
  641. }
  642. static int _dsi_unregister_isr(omap_dsi_isr_t isr, void *arg, u32 mask,
  643. struct dsi_isr_data *isr_array, unsigned isr_array_size)
  644. {
  645. struct dsi_isr_data *isr_data;
  646. int i;
  647. for (i = 0; i < isr_array_size; i++) {
  648. isr_data = &isr_array[i];
  649. if (isr_data->isr != isr || isr_data->arg != arg ||
  650. isr_data->mask != mask)
  651. continue;
  652. isr_data->isr = NULL;
  653. isr_data->arg = NULL;
  654. isr_data->mask = 0;
  655. return 0;
  656. }
  657. return -EINVAL;
  658. }
  659. static int dsi_register_isr(omap_dsi_isr_t isr, void *arg, u32 mask)
  660. {
  661. unsigned long flags;
  662. int r;
  663. spin_lock_irqsave(&dsi.irq_lock, flags);
  664. r = _dsi_register_isr(isr, arg, mask, dsi.isr_tables.isr_table,
  665. ARRAY_SIZE(dsi.isr_tables.isr_table));
  666. if (r == 0)
  667. _omap_dsi_set_irqs();
  668. spin_unlock_irqrestore(&dsi.irq_lock, flags);
  669. return r;
  670. }
  671. static int dsi_unregister_isr(omap_dsi_isr_t isr, void *arg, u32 mask)
  672. {
  673. unsigned long flags;
  674. int r;
  675. spin_lock_irqsave(&dsi.irq_lock, flags);
  676. r = _dsi_unregister_isr(isr, arg, mask, dsi.isr_tables.isr_table,
  677. ARRAY_SIZE(dsi.isr_tables.isr_table));
  678. if (r == 0)
  679. _omap_dsi_set_irqs();
  680. spin_unlock_irqrestore(&dsi.irq_lock, flags);
  681. return r;
  682. }
  683. static int dsi_register_isr_vc(int channel, omap_dsi_isr_t isr, void *arg,
  684. u32 mask)
  685. {
  686. unsigned long flags;
  687. int r;
  688. spin_lock_irqsave(&dsi.irq_lock, flags);
  689. r = _dsi_register_isr(isr, arg, mask,
  690. dsi.isr_tables.isr_table_vc[channel],
  691. ARRAY_SIZE(dsi.isr_tables.isr_table_vc[channel]));
  692. if (r == 0)
  693. _omap_dsi_set_irqs_vc(channel);
  694. spin_unlock_irqrestore(&dsi.irq_lock, flags);
  695. return r;
  696. }
  697. static int dsi_unregister_isr_vc(int channel, omap_dsi_isr_t isr, void *arg,
  698. u32 mask)
  699. {
  700. unsigned long flags;
  701. int r;
  702. spin_lock_irqsave(&dsi.irq_lock, flags);
  703. r = _dsi_unregister_isr(isr, arg, mask,
  704. dsi.isr_tables.isr_table_vc[channel],
  705. ARRAY_SIZE(dsi.isr_tables.isr_table_vc[channel]));
  706. if (r == 0)
  707. _omap_dsi_set_irqs_vc(channel);
  708. spin_unlock_irqrestore(&dsi.irq_lock, flags);
  709. return r;
  710. }
  711. static int dsi_register_isr_cio(omap_dsi_isr_t isr, void *arg, u32 mask)
  712. {
  713. unsigned long flags;
  714. int r;
  715. spin_lock_irqsave(&dsi.irq_lock, flags);
  716. r = _dsi_register_isr(isr, arg, mask, dsi.isr_tables.isr_table_cio,
  717. ARRAY_SIZE(dsi.isr_tables.isr_table_cio));
  718. if (r == 0)
  719. _omap_dsi_set_irqs_cio();
  720. spin_unlock_irqrestore(&dsi.irq_lock, flags);
  721. return r;
  722. }
  723. static int dsi_unregister_isr_cio(omap_dsi_isr_t isr, void *arg, u32 mask)
  724. {
  725. unsigned long flags;
  726. int r;
  727. spin_lock_irqsave(&dsi.irq_lock, flags);
  728. r = _dsi_unregister_isr(isr, arg, mask, dsi.isr_tables.isr_table_cio,
  729. ARRAY_SIZE(dsi.isr_tables.isr_table_cio));
  730. if (r == 0)
  731. _omap_dsi_set_irqs_cio();
  732. spin_unlock_irqrestore(&dsi.irq_lock, flags);
  733. return r;
  734. }
  735. static u32 dsi_get_errors(void)
  736. {
  737. unsigned long flags;
  738. u32 e;
  739. spin_lock_irqsave(&dsi.errors_lock, flags);
  740. e = dsi.errors;
  741. dsi.errors = 0;
  742. spin_unlock_irqrestore(&dsi.errors_lock, flags);
  743. return e;
  744. }
  745. /* DSI func clock. this could also be dsi_pll_hsdiv_dsi_clk */
  746. static inline void enable_clocks(bool enable)
  747. {
  748. if (enable)
  749. dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK);
  750. else
  751. dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK);
  752. }
  753. /* source clock for DSI PLL. this could also be PCLKFREE */
  754. static inline void dsi_enable_pll_clock(bool enable)
  755. {
  756. if (enable)
  757. dss_clk_enable(DSS_CLK_SYSCK);
  758. else
  759. dss_clk_disable(DSS_CLK_SYSCK);
  760. if (enable && dsi.pll_locked) {
  761. if (wait_for_bit_change(DSI_PLL_STATUS, 1, 1) != 1)
  762. DSSERR("cannot lock PLL when enabling clocks\n");
  763. }
  764. }
  765. #ifdef DEBUG
  766. static void _dsi_print_reset_status(void)
  767. {
  768. u32 l;
  769. if (!dss_debug)
  770. return;
  771. /* A dummy read using the SCP interface to any DSIPHY register is
  772. * required after DSIPHY reset to complete the reset of the DSI complex
  773. * I/O. */
  774. l = dsi_read_reg(DSI_DSIPHY_CFG5);
  775. printk(KERN_DEBUG "DSI resets: ");
  776. l = dsi_read_reg(DSI_PLL_STATUS);
  777. printk("PLL (%d) ", FLD_GET(l, 0, 0));
  778. l = dsi_read_reg(DSI_COMPLEXIO_CFG1);
  779. printk("CIO (%d) ", FLD_GET(l, 29, 29));
  780. l = dsi_read_reg(DSI_DSIPHY_CFG5);
  781. printk("PHY (%x, %d, %d, %d)\n",
  782. FLD_GET(l, 28, 26),
  783. FLD_GET(l, 29, 29),
  784. FLD_GET(l, 30, 30),
  785. FLD_GET(l, 31, 31));
  786. }
  787. #else
  788. #define _dsi_print_reset_status()
  789. #endif
  790. static inline int dsi_if_enable(bool enable)
  791. {
  792. DSSDBG("dsi_if_enable(%d)\n", enable);
  793. enable = enable ? 1 : 0;
  794. REG_FLD_MOD(DSI_CTRL, enable, 0, 0); /* IF_EN */
  795. if (wait_for_bit_change(DSI_CTRL, 0, enable) != enable) {
  796. DSSERR("Failed to set dsi_if_enable to %d\n", enable);
  797. return -EIO;
  798. }
  799. return 0;
  800. }
  801. unsigned long dsi_get_pll_hsdiv_dispc_rate(void)
  802. {
  803. return dsi.current_cinfo.dsi_pll_hsdiv_dispc_clk;
  804. }
  805. static unsigned long dsi_get_pll_hsdiv_dsi_rate(void)
  806. {
  807. return dsi.current_cinfo.dsi_pll_hsdiv_dsi_clk;
  808. }
  809. static unsigned long dsi_get_txbyteclkhs(void)
  810. {
  811. return dsi.current_cinfo.clkin4ddr / 16;
  812. }
  813. static unsigned long dsi_fclk_rate(void)
  814. {
  815. unsigned long r;
  816. if (dss_get_dsi_clk_source() == DSS_CLK_SRC_FCK) {
  817. /* DSI FCLK source is DSS_CLK_FCK */
  818. r = dss_clk_get_rate(DSS_CLK_FCK);
  819. } else {
  820. /* DSI FCLK source is dsi_pll_hsdiv_dsi_clk */
  821. r = dsi_get_pll_hsdiv_dsi_rate();
  822. }
  823. return r;
  824. }
  825. static int dsi_set_lp_clk_divisor(struct omap_dss_device *dssdev)
  826. {
  827. unsigned long dsi_fclk;
  828. unsigned lp_clk_div;
  829. unsigned long lp_clk;
  830. lp_clk_div = dssdev->phy.dsi.div.lp_clk_div;
  831. if (lp_clk_div == 0 || lp_clk_div > dsi.lpdiv_max)
  832. return -EINVAL;
  833. dsi_fclk = dsi_fclk_rate();
  834. lp_clk = dsi_fclk / 2 / lp_clk_div;
  835. DSSDBG("LP_CLK_DIV %u, LP_CLK %lu\n", lp_clk_div, lp_clk);
  836. dsi.current_cinfo.lp_clk = lp_clk;
  837. dsi.current_cinfo.lp_clk_div = lp_clk_div;
  838. REG_FLD_MOD(DSI_CLK_CTRL, lp_clk_div, 12, 0); /* LP_CLK_DIVISOR */
  839. REG_FLD_MOD(DSI_CLK_CTRL, dsi_fclk > 30000000 ? 1 : 0,
  840. 21, 21); /* LP_RX_SYNCHRO_ENABLE */
  841. return 0;
  842. }
  843. enum dsi_pll_power_state {
  844. DSI_PLL_POWER_OFF = 0x0,
  845. DSI_PLL_POWER_ON_HSCLK = 0x1,
  846. DSI_PLL_POWER_ON_ALL = 0x2,
  847. DSI_PLL_POWER_ON_DIV = 0x3,
  848. };
  849. static int dsi_pll_power(enum dsi_pll_power_state state)
  850. {
  851. int t = 0;
  852. REG_FLD_MOD(DSI_CLK_CTRL, state, 31, 30); /* PLL_PWR_CMD */
  853. /* PLL_PWR_STATUS */
  854. while (FLD_GET(dsi_read_reg(DSI_CLK_CTRL), 29, 28) != state) {
  855. if (++t > 1000) {
  856. DSSERR("Failed to set DSI PLL power mode to %d\n",
  857. state);
  858. return -ENODEV;
  859. }
  860. udelay(1);
  861. }
  862. return 0;
  863. }
  864. /* calculate clock rates using dividers in cinfo */
  865. static int dsi_calc_clock_rates(struct omap_dss_device *dssdev,
  866. struct dsi_clock_info *cinfo)
  867. {
  868. if (cinfo->regn == 0 || cinfo->regn > dsi.regn_max)
  869. return -EINVAL;
  870. if (cinfo->regm == 0 || cinfo->regm > dsi.regm_max)
  871. return -EINVAL;
  872. if (cinfo->regm_dispc > dsi.regm_dispc_max)
  873. return -EINVAL;
  874. if (cinfo->regm_dsi > dsi.regm_dsi_max)
  875. return -EINVAL;
  876. if (cinfo->use_sys_clk) {
  877. cinfo->clkin = dss_clk_get_rate(DSS_CLK_SYSCK);
  878. /* XXX it is unclear if highfreq should be used
  879. * with DSS_SYS_CLK source also */
  880. cinfo->highfreq = 0;
  881. } else {
  882. cinfo->clkin = dispc_pclk_rate(dssdev->manager->id);
  883. if (cinfo->clkin < 32000000)
  884. cinfo->highfreq = 0;
  885. else
  886. cinfo->highfreq = 1;
  887. }
  888. cinfo->fint = cinfo->clkin / (cinfo->regn * (cinfo->highfreq ? 2 : 1));
  889. if (cinfo->fint > dsi.fint_max || cinfo->fint < dsi.fint_min)
  890. return -EINVAL;
  891. cinfo->clkin4ddr = 2 * cinfo->regm * cinfo->fint;
  892. if (cinfo->clkin4ddr > 1800 * 1000 * 1000)
  893. return -EINVAL;
  894. if (cinfo->regm_dispc > 0)
  895. cinfo->dsi_pll_hsdiv_dispc_clk =
  896. cinfo->clkin4ddr / cinfo->regm_dispc;
  897. else
  898. cinfo->dsi_pll_hsdiv_dispc_clk = 0;
  899. if (cinfo->regm_dsi > 0)
  900. cinfo->dsi_pll_hsdiv_dsi_clk =
  901. cinfo->clkin4ddr / cinfo->regm_dsi;
  902. else
  903. cinfo->dsi_pll_hsdiv_dsi_clk = 0;
  904. return 0;
  905. }
  906. int dsi_pll_calc_clock_div_pck(bool is_tft, unsigned long req_pck,
  907. struct dsi_clock_info *dsi_cinfo,
  908. struct dispc_clock_info *dispc_cinfo)
  909. {
  910. struct dsi_clock_info cur, best;
  911. struct dispc_clock_info best_dispc;
  912. int min_fck_per_pck;
  913. int match = 0;
  914. unsigned long dss_sys_clk, max_dss_fck;
  915. dss_sys_clk = dss_clk_get_rate(DSS_CLK_SYSCK);
  916. max_dss_fck = dss_feat_get_param_max(FEAT_PARAM_DSS_FCK);
  917. if (req_pck == dsi.cache_req_pck &&
  918. dsi.cache_cinfo.clkin == dss_sys_clk) {
  919. DSSDBG("DSI clock info found from cache\n");
  920. *dsi_cinfo = dsi.cache_cinfo;
  921. dispc_find_clk_divs(is_tft, req_pck,
  922. dsi_cinfo->dsi_pll_hsdiv_dispc_clk, dispc_cinfo);
  923. return 0;
  924. }
  925. min_fck_per_pck = CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK;
  926. if (min_fck_per_pck &&
  927. req_pck * min_fck_per_pck > max_dss_fck) {
  928. DSSERR("Requested pixel clock not possible with the current "
  929. "OMAP2_DSS_MIN_FCK_PER_PCK setting. Turning "
  930. "the constraint off.\n");
  931. min_fck_per_pck = 0;
  932. }
  933. DSSDBG("dsi_pll_calc\n");
  934. retry:
  935. memset(&best, 0, sizeof(best));
  936. memset(&best_dispc, 0, sizeof(best_dispc));
  937. memset(&cur, 0, sizeof(cur));
  938. cur.clkin = dss_sys_clk;
  939. cur.use_sys_clk = 1;
  940. cur.highfreq = 0;
  941. /* no highfreq: 0.75MHz < Fint = clkin / regn < 2.1MHz */
  942. /* highfreq: 0.75MHz < Fint = clkin / (2*regn) < 2.1MHz */
  943. /* To reduce PLL lock time, keep Fint high (around 2 MHz) */
  944. for (cur.regn = 1; cur.regn < dsi.regn_max; ++cur.regn) {
  945. if (cur.highfreq == 0)
  946. cur.fint = cur.clkin / cur.regn;
  947. else
  948. cur.fint = cur.clkin / (2 * cur.regn);
  949. if (cur.fint > dsi.fint_max || cur.fint < dsi.fint_min)
  950. continue;
  951. /* DSIPHY(MHz) = (2 * regm / regn) * (clkin / (highfreq + 1)) */
  952. for (cur.regm = 1; cur.regm < dsi.regm_max; ++cur.regm) {
  953. unsigned long a, b;
  954. a = 2 * cur.regm * (cur.clkin/1000);
  955. b = cur.regn * (cur.highfreq + 1);
  956. cur.clkin4ddr = a / b * 1000;
  957. if (cur.clkin4ddr > 1800 * 1000 * 1000)
  958. break;
  959. /* dsi_pll_hsdiv_dispc_clk(MHz) =
  960. * DSIPHY(MHz) / regm_dispc < 173MHz/186Mhz */
  961. for (cur.regm_dispc = 1; cur.regm_dispc < dsi.regm_dispc_max;
  962. ++cur.regm_dispc) {
  963. struct dispc_clock_info cur_dispc;
  964. cur.dsi_pll_hsdiv_dispc_clk =
  965. cur.clkin4ddr / cur.regm_dispc;
  966. /* this will narrow down the search a bit,
  967. * but still give pixclocks below what was
  968. * requested */
  969. if (cur.dsi_pll_hsdiv_dispc_clk < req_pck)
  970. break;
  971. if (cur.dsi_pll_hsdiv_dispc_clk > max_dss_fck)
  972. continue;
  973. if (min_fck_per_pck &&
  974. cur.dsi_pll_hsdiv_dispc_clk <
  975. req_pck * min_fck_per_pck)
  976. continue;
  977. match = 1;
  978. dispc_find_clk_divs(is_tft, req_pck,
  979. cur.dsi_pll_hsdiv_dispc_clk,
  980. &cur_dispc);
  981. if (abs(cur_dispc.pck - req_pck) <
  982. abs(best_dispc.pck - req_pck)) {
  983. best = cur;
  984. best_dispc = cur_dispc;
  985. if (cur_dispc.pck == req_pck)
  986. goto found;
  987. }
  988. }
  989. }
  990. }
  991. found:
  992. if (!match) {
  993. if (min_fck_per_pck) {
  994. DSSERR("Could not find suitable clock settings.\n"
  995. "Turning FCK/PCK constraint off and"
  996. "trying again.\n");
  997. min_fck_per_pck = 0;
  998. goto retry;
  999. }
  1000. DSSERR("Could not find suitable clock settings.\n");
  1001. return -EINVAL;
  1002. }
  1003. /* dsi_pll_hsdiv_dsi_clk (regm_dsi) is not used */
  1004. best.regm_dsi = 0;
  1005. best.dsi_pll_hsdiv_dsi_clk = 0;
  1006. if (dsi_cinfo)
  1007. *dsi_cinfo = best;
  1008. if (dispc_cinfo)
  1009. *dispc_cinfo = best_dispc;
  1010. dsi.cache_req_pck = req_pck;
  1011. dsi.cache_clk_freq = 0;
  1012. dsi.cache_cinfo = best;
  1013. return 0;
  1014. }
  1015. int dsi_pll_set_clock_div(struct dsi_clock_info *cinfo)
  1016. {
  1017. int r = 0;
  1018. u32 l;
  1019. int f;
  1020. u8 regn_start, regn_end, regm_start, regm_end;
  1021. u8 regm_dispc_start, regm_dispc_end, regm_dsi_start, regm_dsi_end;
  1022. DSSDBGF();
  1023. dsi.current_cinfo.fint = cinfo->fint;
  1024. dsi.current_cinfo.clkin4ddr = cinfo->clkin4ddr;
  1025. dsi.current_cinfo.dsi_pll_hsdiv_dispc_clk =
  1026. cinfo->dsi_pll_hsdiv_dispc_clk;
  1027. dsi.current_cinfo.dsi_pll_hsdiv_dsi_clk =
  1028. cinfo->dsi_pll_hsdiv_dsi_clk;
  1029. dsi.current_cinfo.regn = cinfo->regn;
  1030. dsi.current_cinfo.regm = cinfo->regm;
  1031. dsi.current_cinfo.regm_dispc = cinfo->regm_dispc;
  1032. dsi.current_cinfo.regm_dsi = cinfo->regm_dsi;
  1033. DSSDBG("DSI Fint %ld\n", cinfo->fint);
  1034. DSSDBG("clkin (%s) rate %ld, highfreq %d\n",
  1035. cinfo->use_sys_clk ? "dss_sys_clk" : "pclkfree",
  1036. cinfo->clkin,
  1037. cinfo->highfreq);
  1038. /* DSIPHY == CLKIN4DDR */
  1039. DSSDBG("CLKIN4DDR = 2 * %d / %d * %lu / %d = %lu\n",
  1040. cinfo->regm,
  1041. cinfo->regn,
  1042. cinfo->clkin,
  1043. cinfo->highfreq + 1,
  1044. cinfo->clkin4ddr);
  1045. DSSDBG("Data rate on 1 DSI lane %ld Mbps\n",
  1046. cinfo->clkin4ddr / 1000 / 1000 / 2);
  1047. DSSDBG("Clock lane freq %ld Hz\n", cinfo->clkin4ddr / 4);
  1048. DSSDBG("regm_dispc = %d, %s (%s) = %lu\n", cinfo->regm_dispc,
  1049. dss_get_generic_clk_source_name(DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC),
  1050. dss_feat_get_clk_source_name(DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC),
  1051. cinfo->dsi_pll_hsdiv_dispc_clk);
  1052. DSSDBG("regm_dsi = %d, %s (%s) = %lu\n", cinfo->regm_dsi,
  1053. dss_get_generic_clk_source_name(DSS_CLK_SRC_DSI_PLL_HSDIV_DSI),
  1054. dss_feat_get_clk_source_name(DSS_CLK_SRC_DSI_PLL_HSDIV_DSI),
  1055. cinfo->dsi_pll_hsdiv_dsi_clk);
  1056. dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGN, &regn_start, &regn_end);
  1057. dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGM, &regm_start, &regm_end);
  1058. dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGM_DISPC, &regm_dispc_start,
  1059. &regm_dispc_end);
  1060. dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGM_DSI, &regm_dsi_start,
  1061. &regm_dsi_end);
  1062. REG_FLD_MOD(DSI_PLL_CONTROL, 0, 0, 0); /* DSI_PLL_AUTOMODE = manual */
  1063. l = dsi_read_reg(DSI_PLL_CONFIGURATION1);
  1064. l = FLD_MOD(l, 1, 0, 0); /* DSI_PLL_STOPMODE */
  1065. /* DSI_PLL_REGN */
  1066. l = FLD_MOD(l, cinfo->regn - 1, regn_start, regn_end);
  1067. /* DSI_PLL_REGM */
  1068. l = FLD_MOD(l, cinfo->regm, regm_start, regm_end);
  1069. /* DSI_CLOCK_DIV */
  1070. l = FLD_MOD(l, cinfo->regm_dispc > 0 ? cinfo->regm_dispc - 1 : 0,
  1071. regm_dispc_start, regm_dispc_end);
  1072. /* DSIPROTO_CLOCK_DIV */
  1073. l = FLD_MOD(l, cinfo->regm_dsi > 0 ? cinfo->regm_dsi - 1 : 0,
  1074. regm_dsi_start, regm_dsi_end);
  1075. dsi_write_reg(DSI_PLL_CONFIGURATION1, l);
  1076. BUG_ON(cinfo->fint < dsi.fint_min || cinfo->fint > dsi.fint_max);
  1077. if (cinfo->fint < 1000000)
  1078. f = 0x3;
  1079. else if (cinfo->fint < 1250000)
  1080. f = 0x4;
  1081. else if (cinfo->fint < 1500000)
  1082. f = 0x5;
  1083. else if (cinfo->fint < 1750000)
  1084. f = 0x6;
  1085. else
  1086. f = 0x7;
  1087. l = dsi_read_reg(DSI_PLL_CONFIGURATION2);
  1088. l = FLD_MOD(l, f, 4, 1); /* DSI_PLL_FREQSEL */
  1089. l = FLD_MOD(l, cinfo->use_sys_clk ? 0 : 1,
  1090. 11, 11); /* DSI_PLL_CLKSEL */
  1091. l = FLD_MOD(l, cinfo->highfreq,
  1092. 12, 12); /* DSI_PLL_HIGHFREQ */
  1093. l = FLD_MOD(l, 1, 13, 13); /* DSI_PLL_REFEN */
  1094. l = FLD_MOD(l, 0, 14, 14); /* DSIPHY_CLKINEN */
  1095. l = FLD_MOD(l, 1, 20, 20); /* DSI_HSDIVBYPASS */
  1096. dsi_write_reg(DSI_PLL_CONFIGURATION2, l);
  1097. REG_FLD_MOD(DSI_PLL_GO, 1, 0, 0); /* DSI_PLL_GO */
  1098. if (wait_for_bit_change(DSI_PLL_GO, 0, 0) != 0) {
  1099. DSSERR("dsi pll go bit not going down.\n");
  1100. r = -EIO;
  1101. goto err;
  1102. }
  1103. if (wait_for_bit_change(DSI_PLL_STATUS, 1, 1) != 1) {
  1104. DSSERR("cannot lock PLL\n");
  1105. r = -EIO;
  1106. goto err;
  1107. }
  1108. dsi.pll_locked = 1;
  1109. l = dsi_read_reg(DSI_PLL_CONFIGURATION2);
  1110. l = FLD_MOD(l, 0, 0, 0); /* DSI_PLL_IDLE */
  1111. l = FLD_MOD(l, 0, 5, 5); /* DSI_PLL_PLLLPMODE */
  1112. l = FLD_MOD(l, 0, 6, 6); /* DSI_PLL_LOWCURRSTBY */
  1113. l = FLD_MOD(l, 0, 7, 7); /* DSI_PLL_TIGHTPHASELOCK */
  1114. l = FLD_MOD(l, 0, 8, 8); /* DSI_PLL_DRIFTGUARDEN */
  1115. l = FLD_MOD(l, 0, 10, 9); /* DSI_PLL_LOCKSEL */
  1116. l = FLD_MOD(l, 1, 13, 13); /* DSI_PLL_REFEN */
  1117. l = FLD_MOD(l, 1, 14, 14); /* DSIPHY_CLKINEN */
  1118. l = FLD_MOD(l, 0, 15, 15); /* DSI_BYPASSEN */
  1119. l = FLD_MOD(l, 1, 16, 16); /* DSS_CLOCK_EN */
  1120. l = FLD_MOD(l, 0, 17, 17); /* DSS_CLOCK_PWDN */
  1121. l = FLD_MOD(l, 1, 18, 18); /* DSI_PROTO_CLOCK_EN */
  1122. l = FLD_MOD(l, 0, 19, 19); /* DSI_PROTO_CLOCK_PWDN */
  1123. l = FLD_MOD(l, 0, 20, 20); /* DSI_HSDIVBYPASS */
  1124. dsi_write_reg(DSI_PLL_CONFIGURATION2, l);
  1125. DSSDBG("PLL config done\n");
  1126. err:
  1127. return r;
  1128. }
  1129. int dsi_pll_init(struct omap_dss_device *dssdev, bool enable_hsclk,
  1130. bool enable_hsdiv)
  1131. {
  1132. int r = 0;
  1133. enum dsi_pll_power_state pwstate;
  1134. DSSDBG("PLL init\n");
  1135. #ifdef CONFIG_OMAP2_DSS_USE_DSI_PLL
  1136. /*
  1137. * HACK: this is just a quick hack to get the USE_DSI_PLL
  1138. * option working. USE_DSI_PLL is itself a big hack, and
  1139. * should be removed.
  1140. */
  1141. if (dsi.vdds_dsi_reg == NULL) {
  1142. struct regulator *vdds_dsi;
  1143. vdds_dsi = regulator_get(&dsi.pdev->dev, "vdds_dsi");
  1144. if (IS_ERR(vdds_dsi)) {
  1145. DSSERR("can't get VDDS_DSI regulator\n");
  1146. return PTR_ERR(vdds_dsi);
  1147. }
  1148. dsi.vdds_dsi_reg = vdds_dsi;
  1149. }
  1150. #endif
  1151. enable_clocks(1);
  1152. dsi_enable_pll_clock(1);
  1153. r = regulator_enable(dsi.vdds_dsi_reg);
  1154. if (r)
  1155. goto err0;
  1156. /* XXX PLL does not come out of reset without this... */
  1157. dispc_pck_free_enable(1);
  1158. if (wait_for_bit_change(DSI_PLL_STATUS, 0, 1) != 1) {
  1159. DSSERR("PLL not coming out of reset.\n");
  1160. r = -ENODEV;
  1161. dispc_pck_free_enable(0);
  1162. goto err1;
  1163. }
  1164. /* XXX ... but if left on, we get problems when planes do not
  1165. * fill the whole display. No idea about this */
  1166. dispc_pck_free_enable(0);
  1167. if (enable_hsclk && enable_hsdiv)
  1168. pwstate = DSI_PLL_POWER_ON_ALL;
  1169. else if (enable_hsclk)
  1170. pwstate = DSI_PLL_POWER_ON_HSCLK;
  1171. else if (enable_hsdiv)
  1172. pwstate = DSI_PLL_POWER_ON_DIV;
  1173. else
  1174. pwstate = DSI_PLL_POWER_OFF;
  1175. r = dsi_pll_power(pwstate);
  1176. if (r)
  1177. goto err1;
  1178. DSSDBG("PLL init done\n");
  1179. return 0;
  1180. err1:
  1181. regulator_disable(dsi.vdds_dsi_reg);
  1182. err0:
  1183. enable_clocks(0);
  1184. dsi_enable_pll_clock(0);
  1185. return r;
  1186. }
  1187. void dsi_pll_uninit(void)
  1188. {
  1189. enable_clocks(0);
  1190. dsi_enable_pll_clock(0);
  1191. dsi.pll_locked = 0;
  1192. dsi_pll_power(DSI_PLL_POWER_OFF);
  1193. regulator_disable(dsi.vdds_dsi_reg);
  1194. DSSDBG("PLL uninit done\n");
  1195. }
  1196. void dsi_dump_clocks(struct seq_file *s)
  1197. {
  1198. int clksel;
  1199. struct dsi_clock_info *cinfo = &dsi.current_cinfo;
  1200. enum dss_clk_source dispc_clk_src, dsi_clk_src;
  1201. dispc_clk_src = dss_get_dispc_clk_source();
  1202. dsi_clk_src = dss_get_dsi_clk_source();
  1203. enable_clocks(1);
  1204. clksel = REG_GET(DSI_PLL_CONFIGURATION2, 11, 11);
  1205. seq_printf(s, "- DSI PLL -\n");
  1206. seq_printf(s, "dsi pll source = %s\n",
  1207. clksel == 0 ?
  1208. "dss_sys_clk" : "pclkfree");
  1209. seq_printf(s, "Fint\t\t%-16luregn %u\n", cinfo->fint, cinfo->regn);
  1210. seq_printf(s, "CLKIN4DDR\t%-16luregm %u\n",
  1211. cinfo->clkin4ddr, cinfo->regm);
  1212. seq_printf(s, "%s (%s)\t%-16luregm_dispc %u\t(%s)\n",
  1213. dss_get_generic_clk_source_name(dispc_clk_src),
  1214. dss_feat_get_clk_source_name(dispc_clk_src),
  1215. cinfo->dsi_pll_hsdiv_dispc_clk,
  1216. cinfo->regm_dispc,
  1217. dispc_clk_src == DSS_CLK_SRC_FCK ?
  1218. "off" : "on");
  1219. seq_printf(s, "%s (%s)\t%-16luregm_dsi %u\t(%s)\n",
  1220. dss_get_generic_clk_source_name(dsi_clk_src),
  1221. dss_feat_get_clk_source_name(dsi_clk_src),
  1222. cinfo->dsi_pll_hsdiv_dsi_clk,
  1223. cinfo->regm_dsi,
  1224. dsi_clk_src == DSS_CLK_SRC_FCK ?
  1225. "off" : "on");
  1226. seq_printf(s, "- DSI -\n");
  1227. seq_printf(s, "dsi fclk source = %s (%s)\n",
  1228. dss_get_generic_clk_source_name(dsi_clk_src),
  1229. dss_feat_get_clk_source_name(dsi_clk_src));
  1230. seq_printf(s, "DSI_FCLK\t%lu\n", dsi_fclk_rate());
  1231. seq_printf(s, "DDR_CLK\t\t%lu\n",
  1232. cinfo->clkin4ddr / 4);
  1233. seq_printf(s, "TxByteClkHS\t%lu\n", dsi_get_txbyteclkhs());
  1234. seq_printf(s, "LP_CLK\t\t%lu\n", cinfo->lp_clk);
  1235. seq_printf(s, "VP_CLK\t\t%lu\n"
  1236. "VP_PCLK\t\t%lu\n",
  1237. dispc_lclk_rate(OMAP_DSS_CHANNEL_LCD),
  1238. dispc_pclk_rate(OMAP_DSS_CHANNEL_LCD));
  1239. enable_clocks(0);
  1240. }
  1241. #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
  1242. void dsi_dump_irqs(struct seq_file *s)
  1243. {
  1244. unsigned long flags;
  1245. struct dsi_irq_stats stats;
  1246. spin_lock_irqsave(&dsi.irq_stats_lock, flags);
  1247. stats = dsi.irq_stats;
  1248. memset(&dsi.irq_stats, 0, sizeof(dsi.irq_stats));
  1249. dsi.irq_stats.last_reset = jiffies;
  1250. spin_unlock_irqrestore(&dsi.irq_stats_lock, flags);
  1251. seq_printf(s, "period %u ms\n",
  1252. jiffies_to_msecs(jiffies - stats.last_reset));
  1253. seq_printf(s, "irqs %d\n", stats.irq_count);
  1254. #define PIS(x) \
  1255. seq_printf(s, "%-20s %10d\n", #x, stats.dsi_irqs[ffs(DSI_IRQ_##x)-1]);
  1256. seq_printf(s, "-- DSI interrupts --\n");
  1257. PIS(VC0);
  1258. PIS(VC1);
  1259. PIS(VC2);
  1260. PIS(VC3);
  1261. PIS(WAKEUP);
  1262. PIS(RESYNC);
  1263. PIS(PLL_LOCK);
  1264. PIS(PLL_UNLOCK);
  1265. PIS(PLL_RECALL);
  1266. PIS(COMPLEXIO_ERR);
  1267. PIS(HS_TX_TIMEOUT);
  1268. PIS(LP_RX_TIMEOUT);
  1269. PIS(TE_TRIGGER);
  1270. PIS(ACK_TRIGGER);
  1271. PIS(SYNC_LOST);
  1272. PIS(LDO_POWER_GOOD);
  1273. PIS(TA_TIMEOUT);
  1274. #undef PIS
  1275. #define PIS(x) \
  1276. seq_printf(s, "%-20s %10d %10d %10d %10d\n", #x, \
  1277. stats.vc_irqs[0][ffs(DSI_VC_IRQ_##x)-1], \
  1278. stats.vc_irqs[1][ffs(DSI_VC_IRQ_##x)-1], \
  1279. stats.vc_irqs[2][ffs(DSI_VC_IRQ_##x)-1], \
  1280. stats.vc_irqs[3][ffs(DSI_VC_IRQ_##x)-1]);
  1281. seq_printf(s, "-- VC interrupts --\n");
  1282. PIS(CS);
  1283. PIS(ECC_CORR);
  1284. PIS(PACKET_SENT);
  1285. PIS(FIFO_TX_OVF);
  1286. PIS(FIFO_RX_OVF);
  1287. PIS(BTA);
  1288. PIS(ECC_NO_CORR);
  1289. PIS(FIFO_TX_UDF);
  1290. PIS(PP_BUSY_CHANGE);
  1291. #undef PIS
  1292. #define PIS(x) \
  1293. seq_printf(s, "%-20s %10d\n", #x, \
  1294. stats.cio_irqs[ffs(DSI_CIO_IRQ_##x)-1]);
  1295. seq_printf(s, "-- CIO interrupts --\n");
  1296. PIS(ERRSYNCESC1);
  1297. PIS(ERRSYNCESC2);
  1298. PIS(ERRSYNCESC3);
  1299. PIS(ERRESC1);
  1300. PIS(ERRESC2);
  1301. PIS(ERRESC3);
  1302. PIS(ERRCONTROL1);
  1303. PIS(ERRCONTROL2);
  1304. PIS(ERRCONTROL3);
  1305. PIS(STATEULPS1);
  1306. PIS(STATEULPS2);
  1307. PIS(STATEULPS3);
  1308. PIS(ERRCONTENTIONLP0_1);
  1309. PIS(ERRCONTENTIONLP1_1);
  1310. PIS(ERRCONTENTIONLP0_2);
  1311. PIS(ERRCONTENTIONLP1_2);
  1312. PIS(ERRCONTENTIONLP0_3);
  1313. PIS(ERRCONTENTIONLP1_3);
  1314. PIS(ULPSACTIVENOT_ALL0);
  1315. PIS(ULPSACTIVENOT_ALL1);
  1316. #undef PIS
  1317. }
  1318. #endif
  1319. void dsi_dump_regs(struct seq_file *s)
  1320. {
  1321. #define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, dsi_read_reg(r))
  1322. dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK);
  1323. DUMPREG(DSI_REVISION);
  1324. DUMPREG(DSI_SYSCONFIG);
  1325. DUMPREG(DSI_SYSSTATUS);
  1326. DUMPREG(DSI_IRQSTATUS);
  1327. DUMPREG(DSI_IRQENABLE);
  1328. DUMPREG(DSI_CTRL);
  1329. DUMPREG(DSI_COMPLEXIO_CFG1);
  1330. DUMPREG(DSI_COMPLEXIO_IRQ_STATUS);
  1331. DUMPREG(DSI_COMPLEXIO_IRQ_ENABLE);
  1332. DUMPREG(DSI_CLK_CTRL);
  1333. DUMPREG(DSI_TIMING1);
  1334. DUMPREG(DSI_TIMING2);
  1335. DUMPREG(DSI_VM_TIMING1);
  1336. DUMPREG(DSI_VM_TIMING2);
  1337. DUMPREG(DSI_VM_TIMING3);
  1338. DUMPREG(DSI_CLK_TIMING);
  1339. DUMPREG(DSI_TX_FIFO_VC_SIZE);
  1340. DUMPREG(DSI_RX_FIFO_VC_SIZE);
  1341. DUMPREG(DSI_COMPLEXIO_CFG2);
  1342. DUMPREG(DSI_RX_FIFO_VC_FULLNESS);
  1343. DUMPREG(DSI_VM_TIMING4);
  1344. DUMPREG(DSI_TX_FIFO_VC_EMPTINESS);
  1345. DUMPREG(DSI_VM_TIMING5);
  1346. DUMPREG(DSI_VM_TIMING6);
  1347. DUMPREG(DSI_VM_TIMING7);
  1348. DUMPREG(DSI_STOPCLK_TIMING);
  1349. DUMPREG(DSI_VC_CTRL(0));
  1350. DUMPREG(DSI_VC_TE(0));
  1351. DUMPREG(DSI_VC_LONG_PACKET_HEADER(0));
  1352. DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(0));
  1353. DUMPREG(DSI_VC_SHORT_PACKET_HEADER(0));
  1354. DUMPREG(DSI_VC_IRQSTATUS(0));
  1355. DUMPREG(DSI_VC_IRQENABLE(0));
  1356. DUMPREG(DSI_VC_CTRL(1));
  1357. DUMPREG(DSI_VC_TE(1));
  1358. DUMPREG(DSI_VC_LONG_PACKET_HEADER(1));
  1359. DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(1));
  1360. DUMPREG(DSI_VC_SHORT_PACKET_HEADER(1));
  1361. DUMPREG(DSI_VC_IRQSTATUS(1));
  1362. DUMPREG(DSI_VC_IRQENABLE(1));
  1363. DUMPREG(DSI_VC_CTRL(2));
  1364. DUMPREG(DSI_VC_TE(2));
  1365. DUMPREG(DSI_VC_LONG_PACKET_HEADER(2));
  1366. DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(2));
  1367. DUMPREG(DSI_VC_SHORT_PACKET_HEADER(2));
  1368. DUMPREG(DSI_VC_IRQSTATUS(2));
  1369. DUMPREG(DSI_VC_IRQENABLE(2));
  1370. DUMPREG(DSI_VC_CTRL(3));
  1371. DUMPREG(DSI_VC_TE(3));
  1372. DUMPREG(DSI_VC_LONG_PACKET_HEADER(3));
  1373. DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(3));
  1374. DUMPREG(DSI_VC_SHORT_PACKET_HEADER(3));
  1375. DUMPREG(DSI_VC_IRQSTATUS(3));
  1376. DUMPREG(DSI_VC_IRQENABLE(3));
  1377. DUMPREG(DSI_DSIPHY_CFG0);
  1378. DUMPREG(DSI_DSIPHY_CFG1);
  1379. DUMPREG(DSI_DSIPHY_CFG2);
  1380. DUMPREG(DSI_DSIPHY_CFG5);
  1381. DUMPREG(DSI_PLL_CONTROL);
  1382. DUMPREG(DSI_PLL_STATUS);
  1383. DUMPREG(DSI_PLL_GO);
  1384. DUMPREG(DSI_PLL_CONFIGURATION1);
  1385. DUMPREG(DSI_PLL_CONFIGURATION2);
  1386. dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK);
  1387. #undef DUMPREG
  1388. }
  1389. enum dsi_complexio_power_state {
  1390. DSI_COMPLEXIO_POWER_OFF = 0x0,
  1391. DSI_COMPLEXIO_POWER_ON = 0x1,
  1392. DSI_COMPLEXIO_POWER_ULPS = 0x2,
  1393. };
  1394. static int dsi_complexio_power(enum dsi_complexio_power_state state)
  1395. {
  1396. int t = 0;
  1397. /* PWR_CMD */
  1398. REG_FLD_MOD(DSI_COMPLEXIO_CFG1, state, 28, 27);
  1399. /* PWR_STATUS */
  1400. while (FLD_GET(dsi_read_reg(DSI_COMPLEXIO_CFG1), 26, 25) != state) {
  1401. if (++t > 1000) {
  1402. DSSERR("failed to set complexio power state to "
  1403. "%d\n", state);
  1404. return -ENODEV;
  1405. }
  1406. udelay(1);
  1407. }
  1408. return 0;
  1409. }
  1410. static void dsi_complexio_config(struct omap_dss_device *dssdev)
  1411. {
  1412. u32 r;
  1413. int clk_lane = dssdev->phy.dsi.clk_lane;
  1414. int data1_lane = dssdev->phy.dsi.data1_lane;
  1415. int data2_lane = dssdev->phy.dsi.data2_lane;
  1416. int clk_pol = dssdev->phy.dsi.clk_pol;
  1417. int data1_pol = dssdev->phy.dsi.data1_pol;
  1418. int data2_pol = dssdev->phy.dsi.data2_pol;
  1419. r = dsi_read_reg(DSI_COMPLEXIO_CFG1);
  1420. r = FLD_MOD(r, clk_lane, 2, 0);
  1421. r = FLD_MOD(r, clk_pol, 3, 3);
  1422. r = FLD_MOD(r, data1_lane, 6, 4);
  1423. r = FLD_MOD(r, data1_pol, 7, 7);
  1424. r = FLD_MOD(r, data2_lane, 10, 8);
  1425. r = FLD_MOD(r, data2_pol, 11, 11);
  1426. dsi_write_reg(DSI_COMPLEXIO_CFG1, r);
  1427. /* The configuration of the DSI complex I/O (number of data lanes,
  1428. position, differential order) should not be changed while
  1429. DSS.DSI_CLK_CRTRL[20] LP_CLK_ENABLE bit is set to 1. In order for
  1430. the hardware to take into account a new configuration of the complex
  1431. I/O (done in DSS.DSI_COMPLEXIO_CFG1 register), it is recommended to
  1432. follow this sequence: First set the DSS.DSI_CTRL[0] IF_EN bit to 1,
  1433. then reset the DSS.DSI_CTRL[0] IF_EN to 0, then set
  1434. DSS.DSI_CLK_CTRL[20] LP_CLK_ENABLE to 1 and finally set again the
  1435. DSS.DSI_CTRL[0] IF_EN bit to 1. If the sequence is not followed, the
  1436. DSI complex I/O configuration is unknown. */
  1437. /*
  1438. REG_FLD_MOD(DSI_CTRL, 1, 0, 0);
  1439. REG_FLD_MOD(DSI_CTRL, 0, 0, 0);
  1440. REG_FLD_MOD(DSI_CLK_CTRL, 1, 20, 20);
  1441. REG_FLD_MOD(DSI_CTRL, 1, 0, 0);
  1442. */
  1443. }
  1444. static inline unsigned ns2ddr(unsigned ns)
  1445. {
  1446. /* convert time in ns to ddr ticks, rounding up */
  1447. unsigned long ddr_clk = dsi.current_cinfo.clkin4ddr / 4;
  1448. return (ns * (ddr_clk / 1000 / 1000) + 999) / 1000;
  1449. }
  1450. static inline unsigned ddr2ns(unsigned ddr)
  1451. {
  1452. unsigned long ddr_clk = dsi.current_cinfo.clkin4ddr / 4;
  1453. return ddr * 1000 * 1000 / (ddr_clk / 1000);
  1454. }
  1455. static void dsi_complexio_timings(void)
  1456. {
  1457. u32 r;
  1458. u32 ths_prepare, ths_prepare_ths_zero, ths_trail, ths_exit;
  1459. u32 tlpx_half, tclk_trail, tclk_zero;
  1460. u32 tclk_prepare;
  1461. /* calculate timings */
  1462. /* 1 * DDR_CLK = 2 * UI */
  1463. /* min 40ns + 4*UI max 85ns + 6*UI */
  1464. ths_prepare = ns2ddr(70) + 2;
  1465. /* min 145ns + 10*UI */
  1466. ths_prepare_ths_zero = ns2ddr(175) + 2;
  1467. /* min max(8*UI, 60ns+4*UI) */
  1468. ths_trail = ns2ddr(60) + 5;
  1469. /* min 100ns */
  1470. ths_exit = ns2ddr(145);
  1471. /* tlpx min 50n */
  1472. tlpx_half = ns2ddr(25);
  1473. /* min 60ns */
  1474. tclk_trail = ns2ddr(60) + 2;
  1475. /* min 38ns, max 95ns */
  1476. tclk_prepare = ns2ddr(65);
  1477. /* min tclk-prepare + tclk-zero = 300ns */
  1478. tclk_zero = ns2ddr(260);
  1479. DSSDBG("ths_prepare %u (%uns), ths_prepare_ths_zero %u (%uns)\n",
  1480. ths_prepare, ddr2ns(ths_prepare),
  1481. ths_prepare_ths_zero, ddr2ns(ths_prepare_ths_zero));
  1482. DSSDBG("ths_trail %u (%uns), ths_exit %u (%uns)\n",
  1483. ths_trail, ddr2ns(ths_trail),
  1484. ths_exit, ddr2ns(ths_exit));
  1485. DSSDBG("tlpx_half %u (%uns), tclk_trail %u (%uns), "
  1486. "tclk_zero %u (%uns)\n",
  1487. tlpx_half, ddr2ns(tlpx_half),
  1488. tclk_trail, ddr2ns(tclk_trail),
  1489. tclk_zero, ddr2ns(tclk_zero));
  1490. DSSDBG("tclk_prepare %u (%uns)\n",
  1491. tclk_prepare, ddr2ns(tclk_prepare));
  1492. /* program timings */
  1493. r = dsi_read_reg(DSI_DSIPHY_CFG0);
  1494. r = FLD_MOD(r, ths_prepare, 31, 24);
  1495. r = FLD_MOD(r, ths_prepare_ths_zero, 23, 16);
  1496. r = FLD_MOD(r, ths_trail, 15, 8);
  1497. r = FLD_MOD(r, ths_exit, 7, 0);
  1498. dsi_write_reg(DSI_DSIPHY_CFG0, r);
  1499. r = dsi_read_reg(DSI_DSIPHY_CFG1);
  1500. r = FLD_MOD(r, tlpx_half, 22, 16);
  1501. r = FLD_MOD(r, tclk_trail, 15, 8);
  1502. r = FLD_MOD(r, tclk_zero, 7, 0);
  1503. dsi_write_reg(DSI_DSIPHY_CFG1, r);
  1504. r = dsi_read_reg(DSI_DSIPHY_CFG2);
  1505. r = FLD_MOD(r, tclk_prepare, 7, 0);
  1506. dsi_write_reg(DSI_DSIPHY_CFG2, r);
  1507. }
  1508. static int dsi_complexio_init(struct omap_dss_device *dssdev)
  1509. {
  1510. int r = 0;
  1511. DSSDBG("dsi_complexio_init\n");
  1512. /* CIO_CLK_ICG, enable L3 clk to CIO */
  1513. REG_FLD_MOD(DSI_CLK_CTRL, 1, 14, 14);
  1514. /* A dummy read using the SCP interface to any DSIPHY register is
  1515. * required after DSIPHY reset to complete the reset of the DSI complex
  1516. * I/O. */
  1517. dsi_read_reg(DSI_DSIPHY_CFG5);
  1518. if (wait_for_bit_change(DSI_DSIPHY_CFG5, 30, 1) != 1) {
  1519. DSSERR("ComplexIO PHY not coming out of reset.\n");
  1520. r = -ENODEV;
  1521. goto err;
  1522. }
  1523. dsi_complexio_config(dssdev);
  1524. r = dsi_complexio_power(DSI_COMPLEXIO_POWER_ON);
  1525. if (r)
  1526. goto err;
  1527. if (wait_for_bit_change(DSI_COMPLEXIO_CFG1, 29, 1) != 1) {
  1528. DSSERR("ComplexIO not coming out of reset.\n");
  1529. r = -ENODEV;
  1530. goto err;
  1531. }
  1532. if (wait_for_bit_change(DSI_COMPLEXIO_CFG1, 21, 1) != 1) {
  1533. DSSERR("ComplexIO LDO power down.\n");
  1534. r = -ENODEV;
  1535. goto err;
  1536. }
  1537. dsi_complexio_timings();
  1538. /*
  1539. The configuration of the DSI complex I/O (number of data lanes,
  1540. position, differential order) should not be changed while
  1541. DSS.DSI_CLK_CRTRL[20] LP_CLK_ENABLE bit is set to 1. For the
  1542. hardware to recognize a new configuration of the complex I/O (done
  1543. in DSS.DSI_COMPLEXIO_CFG1 register), it is recommended to follow
  1544. this sequence: First set the DSS.DSI_CTRL[0] IF_EN bit to 1, next
  1545. reset the DSS.DSI_CTRL[0] IF_EN to 0, then set DSS.DSI_CLK_CTRL[20]
  1546. LP_CLK_ENABLE to 1, and finally, set again the DSS.DSI_CTRL[0] IF_EN
  1547. bit to 1. If the sequence is not followed, the DSi complex I/O
  1548. configuration is undetermined.
  1549. */
  1550. dsi_if_enable(1);
  1551. dsi_if_enable(0);
  1552. REG_FLD_MOD(DSI_CLK_CTRL, 1, 20, 20); /* LP_CLK_ENABLE */
  1553. dsi_if_enable(1);
  1554. dsi_if_enable(0);
  1555. DSSDBG("CIO init done\n");
  1556. err:
  1557. return r;
  1558. }
  1559. static void dsi_complexio_uninit(void)
  1560. {
  1561. dsi_complexio_power(DSI_COMPLEXIO_POWER_OFF);
  1562. }
  1563. static int _dsi_wait_reset(void)
  1564. {
  1565. int t = 0;
  1566. while (REG_GET(DSI_SYSSTATUS, 0, 0) == 0) {
  1567. if (++t > 5) {
  1568. DSSERR("soft reset failed\n");
  1569. return -ENODEV;
  1570. }
  1571. udelay(1);
  1572. }
  1573. return 0;
  1574. }
  1575. static int _dsi_reset(void)
  1576. {
  1577. /* Soft reset */
  1578. REG_FLD_MOD(DSI_SYSCONFIG, 1, 1, 1);
  1579. return _dsi_wait_reset();
  1580. }
  1581. static void dsi_config_tx_fifo(enum fifo_size size1, enum fifo_size size2,
  1582. enum fifo_size size3, enum fifo_size size4)
  1583. {
  1584. u32 r = 0;
  1585. int add = 0;
  1586. int i;
  1587. dsi.vc[0].fifo_size = size1;
  1588. dsi.vc[1].fifo_size = size2;
  1589. dsi.vc[2].fifo_size = size3;
  1590. dsi.vc[3].fifo_size = size4;
  1591. for (i = 0; i < 4; i++) {
  1592. u8 v;
  1593. int size = dsi.vc[i].fifo_size;
  1594. if (add + size > 4) {
  1595. DSSERR("Illegal FIFO configuration\n");
  1596. BUG();
  1597. }
  1598. v = FLD_VAL(add, 2, 0) | FLD_VAL(size, 7, 4);
  1599. r |= v << (8 * i);
  1600. /*DSSDBG("TX FIFO vc %d: size %d, add %d\n", i, size, add); */
  1601. add += size;
  1602. }
  1603. dsi_write_reg(DSI_TX_FIFO_VC_SIZE, r);
  1604. }
  1605. static void dsi_config_rx_fifo(enum fifo_size size1, enum fifo_size size2,
  1606. enum fifo_size size3, enum fifo_size size4)
  1607. {
  1608. u32 r = 0;
  1609. int add = 0;
  1610. int i;
  1611. dsi.vc[0].fifo_size = size1;
  1612. dsi.vc[1].fifo_size = size2;
  1613. dsi.vc[2].fifo_size = size3;
  1614. dsi.vc[3].fifo_size = size4;
  1615. for (i = 0; i < 4; i++) {
  1616. u8 v;
  1617. int size = dsi.vc[i].fifo_size;
  1618. if (add + size > 4) {
  1619. DSSERR("Illegal FIFO configuration\n");
  1620. BUG();
  1621. }
  1622. v = FLD_VAL(add, 2, 0) | FLD_VAL(size, 7, 4);
  1623. r |= v << (8 * i);
  1624. /*DSSDBG("RX FIFO vc %d: size %d, add %d\n", i, size, add); */
  1625. add += size;
  1626. }
  1627. dsi_write_reg(DSI_RX_FIFO_VC_SIZE, r);
  1628. }
  1629. static int dsi_force_tx_stop_mode_io(void)
  1630. {
  1631. u32 r;
  1632. r = dsi_read_reg(DSI_TIMING1);
  1633. r = FLD_MOD(r, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */
  1634. dsi_write_reg(DSI_TIMING1, r);
  1635. if (wait_for_bit_change(DSI_TIMING1, 15, 0) != 0) {
  1636. DSSERR("TX_STOP bit not going down\n");
  1637. return -EIO;
  1638. }
  1639. return 0;
  1640. }
  1641. static int dsi_vc_enable(int channel, bool enable)
  1642. {
  1643. DSSDBG("dsi_vc_enable channel %d, enable %d\n",
  1644. channel, enable);
  1645. enable = enable ? 1 : 0;
  1646. REG_FLD_MOD(DSI_VC_CTRL(channel), enable, 0, 0);
  1647. if (wait_for_bit_change(DSI_VC_CTRL(channel), 0, enable) != enable) {
  1648. DSSERR("Failed to set dsi_vc_enable to %d\n", enable);
  1649. return -EIO;
  1650. }
  1651. return 0;
  1652. }
  1653. static void dsi_vc_initial_config(int channel)
  1654. {
  1655. u32 r;
  1656. DSSDBGF("%d", channel);
  1657. r = dsi_read_reg(DSI_VC_CTRL(channel));
  1658. if (FLD_GET(r, 15, 15)) /* VC_BUSY */
  1659. DSSERR("VC(%d) busy when trying to configure it!\n",
  1660. channel);
  1661. r = FLD_MOD(r, 0, 1, 1); /* SOURCE, 0 = L4 */
  1662. r = FLD_MOD(r, 0, 2, 2); /* BTA_SHORT_EN */
  1663. r = FLD_MOD(r, 0, 3, 3); /* BTA_LONG_EN */
  1664. r = FLD_MOD(r, 0, 4, 4); /* MODE, 0 = command */
  1665. r = FLD_MOD(r, 1, 7, 7); /* CS_TX_EN */
  1666. r = FLD_MOD(r, 1, 8, 8); /* ECC_TX_EN */
  1667. r = FLD_MOD(r, 0, 9, 9); /* MODE_SPEED, high speed on/off */
  1668. r = FLD_MOD(r, 4, 29, 27); /* DMA_RX_REQ_NB = no dma */
  1669. r = FLD_MOD(r, 4, 23, 21); /* DMA_TX_REQ_NB = no dma */
  1670. dsi_write_reg(DSI_VC_CTRL(channel), r);
  1671. }
  1672. static int dsi_vc_config_l4(int channel)
  1673. {
  1674. if (dsi.vc[channel].mode == DSI_VC_MODE_L4)
  1675. return 0;
  1676. DSSDBGF("%d", channel);
  1677. dsi_vc_enable(channel, 0);
  1678. /* VC_BUSY */
  1679. if (wait_for_bit_change(DSI_VC_CTRL(channel), 15, 0) != 0) {
  1680. DSSERR("vc(%d) busy when trying to config for L4\n", channel);
  1681. return -EIO;
  1682. }
  1683. REG_FLD_MOD(DSI_VC_CTRL(channel), 0, 1, 1); /* SOURCE, 0 = L4 */
  1684. dsi_vc_enable(channel, 1);
  1685. dsi.vc[channel].mode = DSI_VC_MODE_L4;
  1686. return 0;
  1687. }
  1688. static int dsi_vc_config_vp(int channel)
  1689. {
  1690. if (dsi.vc[channel].mode == DSI_VC_MODE_VP)
  1691. return 0;
  1692. DSSDBGF("%d", channel);
  1693. dsi_vc_enable(channel, 0);
  1694. /* VC_BUSY */
  1695. if (wait_for_bit_change(DSI_VC_CTRL(channel), 15, 0) != 0) {
  1696. DSSERR("vc(%d) busy when trying to config for VP\n", channel);
  1697. return -EIO;
  1698. }
  1699. REG_FLD_MOD(DSI_VC_CTRL(channel), 1, 1, 1); /* SOURCE, 1 = video port */
  1700. dsi_vc_enable(channel, 1);
  1701. dsi.vc[channel].mode = DSI_VC_MODE_VP;
  1702. return 0;
  1703. }
  1704. void omapdss_dsi_vc_enable_hs(int channel, bool enable)
  1705. {
  1706. DSSDBG("dsi_vc_enable_hs(%d, %d)\n", channel, enable);
  1707. WARN_ON(!dsi_bus_is_locked());
  1708. dsi_vc_enable(channel, 0);
  1709. dsi_if_enable(0);
  1710. REG_FLD_MOD(DSI_VC_CTRL(channel), enable, 9, 9);
  1711. dsi_vc_enable(channel, 1);
  1712. dsi_if_enable(1);
  1713. dsi_force_tx_stop_mode_io();
  1714. }
  1715. EXPORT_SYMBOL(omapdss_dsi_vc_enable_hs);
  1716. static void dsi_vc_flush_long_data(int channel)
  1717. {
  1718. while (REG_GET(DSI_VC_CTRL(channel), 20, 20)) {
  1719. u32 val;
  1720. val = dsi_read_reg(DSI_VC_SHORT_PACKET_HEADER(channel));
  1721. DSSDBG("\t\tb1 %#02x b2 %#02x b3 %#02x b4 %#02x\n",
  1722. (val >> 0) & 0xff,
  1723. (val >> 8) & 0xff,
  1724. (val >> 16) & 0xff,
  1725. (val >> 24) & 0xff);
  1726. }
  1727. }
  1728. static void dsi_show_rx_ack_with_err(u16 err)
  1729. {
  1730. DSSERR("\tACK with ERROR (%#x):\n", err);
  1731. if (err & (1 << 0))
  1732. DSSERR("\t\tSoT Error\n");
  1733. if (err & (1 << 1))
  1734. DSSERR("\t\tSoT Sync Error\n");
  1735. if (err & (1 << 2))
  1736. DSSERR("\t\tEoT Sync Error\n");
  1737. if (err & (1 << 3))
  1738. DSSERR("\t\tEscape Mode Entry Command Error\n");
  1739. if (err & (1 << 4))
  1740. DSSERR("\t\tLP Transmit Sync Error\n");
  1741. if (err & (1 << 5))
  1742. DSSERR("\t\tHS Receive Timeout Error\n");
  1743. if (err & (1 << 6))
  1744. DSSERR("\t\tFalse Control Error\n");
  1745. if (err & (1 << 7))
  1746. DSSERR("\t\t(reserved7)\n");
  1747. if (err & (1 << 8))
  1748. DSSERR("\t\tECC Error, single-bit (corrected)\n");
  1749. if (err & (1 << 9))
  1750. DSSERR("\t\tECC Error, multi-bit (not corrected)\n");
  1751. if (err & (1 << 10))
  1752. DSSERR("\t\tChecksum Error\n");
  1753. if (err & (1 << 11))
  1754. DSSERR("\t\tData type not recognized\n");
  1755. if (err & (1 << 12))
  1756. DSSERR("\t\tInvalid VC ID\n");
  1757. if (err & (1 << 13))
  1758. DSSERR("\t\tInvalid Transmission Length\n");
  1759. if (err & (1 << 14))
  1760. DSSERR("\t\t(reserved14)\n");
  1761. if (err & (1 << 15))
  1762. DSSERR("\t\tDSI Protocol Violation\n");
  1763. }
  1764. static u16 dsi_vc_flush_receive_data(int channel)
  1765. {
  1766. /* RX_FIFO_NOT_EMPTY */
  1767. while (REG_GET(DSI_VC_CTRL(channel), 20, 20)) {
  1768. u32 val;
  1769. u8 dt;
  1770. val = dsi_read_reg(DSI_VC_SHORT_PACKET_HEADER(channel));
  1771. DSSERR("\trawval %#08x\n", val);
  1772. dt = FLD_GET(val, 5, 0);
  1773. if (dt == DSI_DT_RX_ACK_WITH_ERR) {
  1774. u16 err = FLD_GET(val, 23, 8);
  1775. dsi_show_rx_ack_with_err(err);
  1776. } else if (dt == DSI_DT_RX_SHORT_READ_1) {
  1777. DSSERR("\tDCS short response, 1 byte: %#x\n",
  1778. FLD_GET(val, 23, 8));
  1779. } else if (dt == DSI_DT_RX_SHORT_READ_2) {
  1780. DSSERR("\tDCS short response, 2 byte: %#x\n",
  1781. FLD_GET(val, 23, 8));
  1782. } else if (dt == DSI_DT_RX_DCS_LONG_READ) {
  1783. DSSERR("\tDCS long response, len %d\n",
  1784. FLD_GET(val, 23, 8));
  1785. dsi_vc_flush_long_data(channel);
  1786. } else {
  1787. DSSERR("\tunknown datatype 0x%02x\n", dt);
  1788. }
  1789. }
  1790. return 0;
  1791. }
  1792. static int dsi_vc_send_bta(int channel)
  1793. {
  1794. if (dsi.debug_write || dsi.debug_read)
  1795. DSSDBG("dsi_vc_send_bta %d\n", channel);
  1796. WARN_ON(!dsi_bus_is_locked());
  1797. if (REG_GET(DSI_VC_CTRL(channel), 20, 20)) { /* RX_FIFO_NOT_EMPTY */
  1798. DSSERR("rx fifo not empty when sending BTA, dumping data:\n");
  1799. dsi_vc_flush_receive_data(channel);
  1800. }
  1801. REG_FLD_MOD(DSI_VC_CTRL(channel), 1, 6, 6); /* BTA_EN */
  1802. return 0;
  1803. }
  1804. int dsi_vc_send_bta_sync(int channel)
  1805. {
  1806. DECLARE_COMPLETION_ONSTACK(completion);
  1807. int r = 0;
  1808. u32 err;
  1809. r = dsi_register_isr_vc(channel, dsi_completion_handler,
  1810. &completion, DSI_VC_IRQ_BTA);
  1811. if (r)
  1812. goto err0;
  1813. r = dsi_register_isr(dsi_completion_handler, &completion,
  1814. DSI_IRQ_ERROR_MASK);
  1815. if (r)
  1816. goto err1;
  1817. r = dsi_vc_send_bta(channel);
  1818. if (r)
  1819. goto err2;
  1820. if (wait_for_completion_timeout(&completion,
  1821. msecs_to_jiffies(500)) == 0) {
  1822. DSSERR("Failed to receive BTA\n");
  1823. r = -EIO;
  1824. goto err2;
  1825. }
  1826. err = dsi_get_errors();
  1827. if (err) {
  1828. DSSERR("Error while sending BTA: %x\n", err);
  1829. r = -EIO;
  1830. goto err2;
  1831. }
  1832. err2:
  1833. dsi_unregister_isr(dsi_completion_handler, &completion,
  1834. DSI_IRQ_ERROR_MASK);
  1835. err1:
  1836. dsi_unregister_isr_vc(channel, dsi_completion_handler,
  1837. &completion, DSI_VC_IRQ_BTA);
  1838. err0:
  1839. return r;
  1840. }
  1841. EXPORT_SYMBOL(dsi_vc_send_bta_sync);
  1842. static inline void dsi_vc_write_long_header(int channel, u8 data_type,
  1843. u16 len, u8 ecc)
  1844. {
  1845. u32 val;
  1846. u8 data_id;
  1847. WARN_ON(!dsi_bus_is_locked());
  1848. data_id = data_type | dsi.vc[channel].vc_id << 6;
  1849. val = FLD_VAL(data_id, 7, 0) | FLD_VAL(len, 23, 8) |
  1850. FLD_VAL(ecc, 31, 24);
  1851. dsi_write_reg(DSI_VC_LONG_PACKET_HEADER(channel), val);
  1852. }
  1853. static inline void dsi_vc_write_long_payload(int channel,
  1854. u8 b1, u8 b2, u8 b3, u8 b4)
  1855. {
  1856. u32 val;
  1857. val = b4 << 24 | b3 << 16 | b2 << 8 | b1 << 0;
  1858. /* DSSDBG("\twriting %02x, %02x, %02x, %02x (%#010x)\n",
  1859. b1, b2, b3, b4, val); */
  1860. dsi_write_reg(DSI_VC_LONG_PACKET_PAYLOAD(channel), val);
  1861. }
  1862. static int dsi_vc_send_long(int channel, u8 data_type, u8 *data, u16 len,
  1863. u8 ecc)
  1864. {
  1865. /*u32 val; */
  1866. int i;
  1867. u8 *p;
  1868. int r = 0;
  1869. u8 b1, b2, b3, b4;
  1870. if (dsi.debug_write)
  1871. DSSDBG("dsi_vc_send_long, %d bytes\n", len);
  1872. /* len + header */
  1873. if (dsi.vc[channel].fifo_size * 32 * 4 < len + 4) {
  1874. DSSERR("unable to send long packet: packet too long.\n");
  1875. return -EINVAL;
  1876. }
  1877. dsi_vc_config_l4(channel);
  1878. dsi_vc_write_long_header(channel, data_type, len, ecc);
  1879. p = data;
  1880. for (i = 0; i < len >> 2; i++) {
  1881. if (dsi.debug_write)
  1882. DSSDBG("\tsending full packet %d\n", i);
  1883. b1 = *p++;
  1884. b2 = *p++;
  1885. b3 = *p++;
  1886. b4 = *p++;
  1887. dsi_vc_write_long_payload(channel, b1, b2, b3, b4);
  1888. }
  1889. i = len % 4;
  1890. if (i) {
  1891. b1 = 0; b2 = 0; b3 = 0;
  1892. if (dsi.debug_write)
  1893. DSSDBG("\tsending remainder bytes %d\n", i);
  1894. switch (i) {
  1895. case 3:
  1896. b1 = *p++;
  1897. b2 = *p++;
  1898. b3 = *p++;
  1899. break;
  1900. case 2:
  1901. b1 = *p++;
  1902. b2 = *p++;
  1903. break;
  1904. case 1:
  1905. b1 = *p++;
  1906. break;
  1907. }
  1908. dsi_vc_write_long_payload(channel, b1, b2, b3, 0);
  1909. }
  1910. return r;
  1911. }
  1912. static int dsi_vc_send_short(int channel, u8 data_type, u16 data, u8 ecc)
  1913. {
  1914. u32 r;
  1915. u8 data_id;
  1916. WARN_ON(!dsi_bus_is_locked());
  1917. if (dsi.debug_write)
  1918. DSSDBG("dsi_vc_send_short(ch%d, dt %#x, b1 %#x, b2 %#x)\n",
  1919. channel,
  1920. data_type, data & 0xff, (data >> 8) & 0xff);
  1921. dsi_vc_config_l4(channel);
  1922. if (FLD_GET(dsi_read_reg(DSI_VC_CTRL(channel)), 16, 16)) {
  1923. DSSERR("ERROR FIFO FULL, aborting transfer\n");
  1924. return -EINVAL;
  1925. }
  1926. data_id = data_type | dsi.vc[channel].vc_id << 6;
  1927. r = (data_id << 0) | (data << 8) | (ecc << 24);
  1928. dsi_write_reg(DSI_VC_SHORT_PACKET_HEADER(channel), r);
  1929. return 0;
  1930. }
  1931. int dsi_vc_send_null(int channel)
  1932. {
  1933. u8 nullpkg[] = {0, 0, 0, 0};
  1934. return dsi_vc_send_long(channel, DSI_DT_NULL_PACKET, nullpkg, 4, 0);
  1935. }
  1936. EXPORT_SYMBOL(dsi_vc_send_null);
  1937. int dsi_vc_dcs_write_nosync(int channel, u8 *data, int len)
  1938. {
  1939. int r;
  1940. BUG_ON(len == 0);
  1941. if (len == 1) {
  1942. r = dsi_vc_send_short(channel, DSI_DT_DCS_SHORT_WRITE_0,
  1943. data[0], 0);
  1944. } else if (len == 2) {
  1945. r = dsi_vc_send_short(channel, DSI_DT_DCS_SHORT_WRITE_1,
  1946. data[0] | (data[1] << 8), 0);
  1947. } else {
  1948. /* 0x39 = DCS Long Write */
  1949. r = dsi_vc_send_long(channel, DSI_DT_DCS_LONG_WRITE,
  1950. data, len, 0);
  1951. }
  1952. return r;
  1953. }
  1954. EXPORT_SYMBOL(dsi_vc_dcs_write_nosync);
  1955. int dsi_vc_dcs_write(int channel, u8 *data, int len)
  1956. {
  1957. int r;
  1958. r = dsi_vc_dcs_write_nosync(channel, data, len);
  1959. if (r)
  1960. goto err;
  1961. r = dsi_vc_send_bta_sync(channel);
  1962. if (r)
  1963. goto err;
  1964. if (REG_GET(DSI_VC_CTRL(channel), 20, 20)) { /* RX_FIFO_NOT_EMPTY */
  1965. DSSERR("rx fifo not empty after write, dumping data:\n");
  1966. dsi_vc_flush_receive_data(channel);
  1967. r = -EIO;
  1968. goto err;
  1969. }
  1970. return 0;
  1971. err:
  1972. DSSERR("dsi_vc_dcs_write(ch %d, cmd 0x%02x, len %d) failed\n",
  1973. channel, data[0], len);
  1974. return r;
  1975. }
  1976. EXPORT_SYMBOL(dsi_vc_dcs_write);
  1977. int dsi_vc_dcs_write_0(int channel, u8 dcs_cmd)
  1978. {
  1979. return dsi_vc_dcs_write(channel, &dcs_cmd, 1);
  1980. }
  1981. EXPORT_SYMBOL(dsi_vc_dcs_write_0);
  1982. int dsi_vc_dcs_write_1(int channel, u8 dcs_cmd, u8 param)
  1983. {
  1984. u8 buf[2];
  1985. buf[0] = dcs_cmd;
  1986. buf[1] = param;
  1987. return dsi_vc_dcs_write(channel, buf, 2);
  1988. }
  1989. EXPORT_SYMBOL(dsi_vc_dcs_write_1);
  1990. int dsi_vc_dcs_read(int channel, u8 dcs_cmd, u8 *buf, int buflen)
  1991. {
  1992. u32 val;
  1993. u8 dt;
  1994. int r;
  1995. if (dsi.debug_read)
  1996. DSSDBG("dsi_vc_dcs_read(ch%d, dcs_cmd %x)\n", channel, dcs_cmd);
  1997. r = dsi_vc_send_short(channel, DSI_DT_DCS_READ, dcs_cmd, 0);
  1998. if (r)
  1999. goto err;
  2000. r = dsi_vc_send_bta_sync(channel);
  2001. if (r)
  2002. goto err;
  2003. /* RX_FIFO_NOT_EMPTY */
  2004. if (REG_GET(DSI_VC_CTRL(channel), 20, 20) == 0) {
  2005. DSSERR("RX fifo empty when trying to read.\n");
  2006. r = -EIO;
  2007. goto err;
  2008. }
  2009. val = dsi_read_reg(DSI_VC_SHORT_PACKET_HEADER(channel));
  2010. if (dsi.debug_read)
  2011. DSSDBG("\theader: %08x\n", val);
  2012. dt = FLD_GET(val, 5, 0);
  2013. if (dt == DSI_DT_RX_ACK_WITH_ERR) {
  2014. u16 err = FLD_GET(val, 23, 8);
  2015. dsi_show_rx_ack_with_err(err);
  2016. r = -EIO;
  2017. goto err;
  2018. } else if (dt == DSI_DT_RX_SHORT_READ_1) {
  2019. u8 data = FLD_GET(val, 15, 8);
  2020. if (dsi.debug_read)
  2021. DSSDBG("\tDCS short response, 1 byte: %02x\n", data);
  2022. if (buflen < 1) {
  2023. r = -EIO;
  2024. goto err;
  2025. }
  2026. buf[0] = data;
  2027. return 1;
  2028. } else if (dt == DSI_DT_RX_SHORT_READ_2) {
  2029. u16 data = FLD_GET(val, 23, 8);
  2030. if (dsi.debug_read)
  2031. DSSDBG("\tDCS short response, 2 byte: %04x\n", data);
  2032. if (buflen < 2) {
  2033. r = -EIO;
  2034. goto err;
  2035. }
  2036. buf[0] = data & 0xff;
  2037. buf[1] = (data >> 8) & 0xff;
  2038. return 2;
  2039. } else if (dt == DSI_DT_RX_DCS_LONG_READ) {
  2040. int w;
  2041. int len = FLD_GET(val, 23, 8);
  2042. if (dsi.debug_read)
  2043. DSSDBG("\tDCS long response, len %d\n", len);
  2044. if (len > buflen) {
  2045. r = -EIO;
  2046. goto err;
  2047. }
  2048. /* two byte checksum ends the packet, not included in len */
  2049. for (w = 0; w < len + 2;) {
  2050. int b;
  2051. val = dsi_read_reg(DSI_VC_SHORT_PACKET_HEADER(channel));
  2052. if (dsi.debug_read)
  2053. DSSDBG("\t\t%02x %02x %02x %02x\n",
  2054. (val >> 0) & 0xff,
  2055. (val >> 8) & 0xff,
  2056. (val >> 16) & 0xff,
  2057. (val >> 24) & 0xff);
  2058. for (b = 0; b < 4; ++b) {
  2059. if (w < len)
  2060. buf[w] = (val >> (b * 8)) & 0xff;
  2061. /* we discard the 2 byte checksum */
  2062. ++w;
  2063. }
  2064. }
  2065. return len;
  2066. } else {
  2067. DSSERR("\tunknown datatype 0x%02x\n", dt);
  2068. r = -EIO;
  2069. goto err;
  2070. }
  2071. BUG();
  2072. err:
  2073. DSSERR("dsi_vc_dcs_read(ch %d, cmd 0x%02x) failed\n",
  2074. channel, dcs_cmd);
  2075. return r;
  2076. }
  2077. EXPORT_SYMBOL(dsi_vc_dcs_read);
  2078. int dsi_vc_dcs_read_1(int channel, u8 dcs_cmd, u8 *data)
  2079. {
  2080. int r;
  2081. r = dsi_vc_dcs_read(channel, dcs_cmd, data, 1);
  2082. if (r < 0)
  2083. return r;
  2084. if (r != 1)
  2085. return -EIO;
  2086. return 0;
  2087. }
  2088. EXPORT_SYMBOL(dsi_vc_dcs_read_1);
  2089. int dsi_vc_dcs_read_2(int channel, u8 dcs_cmd, u8 *data1, u8 *data2)
  2090. {
  2091. u8 buf[2];
  2092. int r;
  2093. r = dsi_vc_dcs_read(channel, dcs_cmd, buf, 2);
  2094. if (r < 0)
  2095. return r;
  2096. if (r != 2)
  2097. return -EIO;
  2098. *data1 = buf[0];
  2099. *data2 = buf[1];
  2100. return 0;
  2101. }
  2102. EXPORT_SYMBOL(dsi_vc_dcs_read_2);
  2103. int dsi_vc_set_max_rx_packet_size(int channel, u16 len)
  2104. {
  2105. return dsi_vc_send_short(channel, DSI_DT_SET_MAX_RET_PKG_SIZE,
  2106. len, 0);
  2107. }
  2108. EXPORT_SYMBOL(dsi_vc_set_max_rx_packet_size);
  2109. static void dsi_set_lp_rx_timeout(unsigned ticks, bool x4, bool x16)
  2110. {
  2111. unsigned long fck;
  2112. unsigned long total_ticks;
  2113. u32 r;
  2114. BUG_ON(ticks > 0x1fff);
  2115. /* ticks in DSI_FCK */
  2116. fck = dsi_fclk_rate();
  2117. r = dsi_read_reg(DSI_TIMING2);
  2118. r = FLD_MOD(r, 1, 15, 15); /* LP_RX_TO */
  2119. r = FLD_MOD(r, x16 ? 1 : 0, 14, 14); /* LP_RX_TO_X16 */
  2120. r = FLD_MOD(r, x4 ? 1 : 0, 13, 13); /* LP_RX_TO_X4 */
  2121. r = FLD_MOD(r, ticks, 12, 0); /* LP_RX_COUNTER */
  2122. dsi_write_reg(DSI_TIMING2, r);
  2123. total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1);
  2124. DSSDBG("LP_RX_TO %lu ticks (%#x%s%s) = %lu ns\n",
  2125. total_ticks,
  2126. ticks, x4 ? " x4" : "", x16 ? " x16" : "",
  2127. (total_ticks * 1000) / (fck / 1000 / 1000));
  2128. }
  2129. static void dsi_set_ta_timeout(unsigned ticks, bool x8, bool x16)
  2130. {
  2131. unsigned long fck;
  2132. unsigned long total_ticks;
  2133. u32 r;
  2134. BUG_ON(ticks > 0x1fff);
  2135. /* ticks in DSI_FCK */
  2136. fck = dsi_fclk_rate();
  2137. r = dsi_read_reg(DSI_TIMING1);
  2138. r = FLD_MOD(r, 1, 31, 31); /* TA_TO */
  2139. r = FLD_MOD(r, x16 ? 1 : 0, 30, 30); /* TA_TO_X16 */
  2140. r = FLD_MOD(r, x8 ? 1 : 0, 29, 29); /* TA_TO_X8 */
  2141. r = FLD_MOD(r, ticks, 28, 16); /* TA_TO_COUNTER */
  2142. dsi_write_reg(DSI_TIMING1, r);
  2143. total_ticks = ticks * (x16 ? 16 : 1) * (x8 ? 8 : 1);
  2144. DSSDBG("TA_TO %lu ticks (%#x%s%s) = %lu ns\n",
  2145. total_ticks,
  2146. ticks, x8 ? " x8" : "", x16 ? " x16" : "",
  2147. (total_ticks * 1000) / (fck / 1000 / 1000));
  2148. }
  2149. static void dsi_set_stop_state_counter(unsigned ticks, bool x4, bool x16)
  2150. {
  2151. unsigned long fck;
  2152. unsigned long total_ticks;
  2153. u32 r;
  2154. BUG_ON(ticks > 0x1fff);
  2155. /* ticks in DSI_FCK */
  2156. fck = dsi_fclk_rate();
  2157. r = dsi_read_reg(DSI_TIMING1);
  2158. r = FLD_MOD(r, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */
  2159. r = FLD_MOD(r, x16 ? 1 : 0, 14, 14); /* STOP_STATE_X16_IO */
  2160. r = FLD_MOD(r, x4 ? 1 : 0, 13, 13); /* STOP_STATE_X4_IO */
  2161. r = FLD_MOD(r, ticks, 12, 0); /* STOP_STATE_COUNTER_IO */
  2162. dsi_write_reg(DSI_TIMING1, r);
  2163. total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1);
  2164. DSSDBG("STOP_STATE_COUNTER %lu ticks (%#x%s%s) = %lu ns\n",
  2165. total_ticks,
  2166. ticks, x4 ? " x4" : "", x16 ? " x16" : "",
  2167. (total_ticks * 1000) / (fck / 1000 / 1000));
  2168. }
  2169. static void dsi_set_hs_tx_timeout(unsigned ticks, bool x4, bool x16)
  2170. {
  2171. unsigned long fck;
  2172. unsigned long total_ticks;
  2173. u32 r;
  2174. BUG_ON(ticks > 0x1fff);
  2175. /* ticks in TxByteClkHS */
  2176. fck = dsi_get_txbyteclkhs();
  2177. r = dsi_read_reg(DSI_TIMING2);
  2178. r = FLD_MOD(r, 1, 31, 31); /* HS_TX_TO */
  2179. r = FLD_MOD(r, x16 ? 1 : 0, 30, 30); /* HS_TX_TO_X16 */
  2180. r = FLD_MOD(r, x4 ? 1 : 0, 29, 29); /* HS_TX_TO_X8 (4 really) */
  2181. r = FLD_MOD(r, ticks, 28, 16); /* HS_TX_TO_COUNTER */
  2182. dsi_write_reg(DSI_TIMING2, r);
  2183. total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1);
  2184. DSSDBG("HS_TX_TO %lu ticks (%#x%s%s) = %lu ns\n",
  2185. total_ticks,
  2186. ticks, x4 ? " x4" : "", x16 ? " x16" : "",
  2187. (total_ticks * 1000) / (fck / 1000 / 1000));
  2188. }
  2189. static int dsi_proto_config(struct omap_dss_device *dssdev)
  2190. {
  2191. u32 r;
  2192. int buswidth = 0;
  2193. dsi_config_tx_fifo(DSI_FIFO_SIZE_32,
  2194. DSI_FIFO_SIZE_32,
  2195. DSI_FIFO_SIZE_32,
  2196. DSI_FIFO_SIZE_32);
  2197. dsi_config_rx_fifo(DSI_FIFO_SIZE_32,
  2198. DSI_FIFO_SIZE_32,
  2199. DSI_FIFO_SIZE_32,
  2200. DSI_FIFO_SIZE_32);
  2201. /* XXX what values for the timeouts? */
  2202. dsi_set_stop_state_counter(0x1000, false, false);
  2203. dsi_set_ta_timeout(0x1fff, true, true);
  2204. dsi_set_lp_rx_timeout(0x1fff, true, true);
  2205. dsi_set_hs_tx_timeout(0x1fff, true, true);
  2206. switch (dssdev->ctrl.pixel_size) {
  2207. case 16:
  2208. buswidth = 0;
  2209. break;
  2210. case 18:
  2211. buswidth = 1;
  2212. break;
  2213. case 24:
  2214. buswidth = 2;
  2215. break;
  2216. default:
  2217. BUG();
  2218. }
  2219. r = dsi_read_reg(DSI_CTRL);
  2220. r = FLD_MOD(r, 1, 1, 1); /* CS_RX_EN */
  2221. r = FLD_MOD(r, 1, 2, 2); /* ECC_RX_EN */
  2222. r = FLD_MOD(r, 1, 3, 3); /* TX_FIFO_ARBITRATION */
  2223. r = FLD_MOD(r, 1, 4, 4); /* VP_CLK_RATIO, always 1, see errata*/
  2224. r = FLD_MOD(r, buswidth, 7, 6); /* VP_DATA_BUS_WIDTH */
  2225. r = FLD_MOD(r, 0, 8, 8); /* VP_CLK_POL */
  2226. r = FLD_MOD(r, 2, 13, 12); /* LINE_BUFFER, 2 lines */
  2227. r = FLD_MOD(r, 1, 14, 14); /* TRIGGER_RESET_MODE */
  2228. r = FLD_MOD(r, 1, 19, 19); /* EOT_ENABLE */
  2229. r = FLD_MOD(r, 1, 24, 24); /* DCS_CMD_ENABLE */
  2230. r = FLD_MOD(r, 0, 25, 25); /* DCS_CMD_CODE, 1=start, 0=continue */
  2231. dsi_write_reg(DSI_CTRL, r);
  2232. dsi_vc_initial_config(0);
  2233. dsi_vc_initial_config(1);
  2234. dsi_vc_initial_config(2);
  2235. dsi_vc_initial_config(3);
  2236. return 0;
  2237. }
  2238. static void dsi_proto_timings(struct omap_dss_device *dssdev)
  2239. {
  2240. unsigned tlpx, tclk_zero, tclk_prepare, tclk_trail;
  2241. unsigned tclk_pre, tclk_post;
  2242. unsigned ths_prepare, ths_prepare_ths_zero, ths_zero;
  2243. unsigned ths_trail, ths_exit;
  2244. unsigned ddr_clk_pre, ddr_clk_post;
  2245. unsigned enter_hs_mode_lat, exit_hs_mode_lat;
  2246. unsigned ths_eot;
  2247. u32 r;
  2248. r = dsi_read_reg(DSI_DSIPHY_CFG0);
  2249. ths_prepare = FLD_GET(r, 31, 24);
  2250. ths_prepare_ths_zero = FLD_GET(r, 23, 16);
  2251. ths_zero = ths_prepare_ths_zero - ths_prepare;
  2252. ths_trail = FLD_GET(r, 15, 8);
  2253. ths_exit = FLD_GET(r, 7, 0);
  2254. r = dsi_read_reg(DSI_DSIPHY_CFG1);
  2255. tlpx = FLD_GET(r, 22, 16) * 2;
  2256. tclk_trail = FLD_GET(r, 15, 8);
  2257. tclk_zero = FLD_GET(r, 7, 0);
  2258. r = dsi_read_reg(DSI_DSIPHY_CFG2);
  2259. tclk_prepare = FLD_GET(r, 7, 0);
  2260. /* min 8*UI */
  2261. tclk_pre = 20;
  2262. /* min 60ns + 52*UI */
  2263. tclk_post = ns2ddr(60) + 26;
  2264. /* ths_eot is 2 for 2 datalanes and 4 for 1 datalane */
  2265. if (dssdev->phy.dsi.data1_lane != 0 &&
  2266. dssdev->phy.dsi.data2_lane != 0)
  2267. ths_eot = 2;
  2268. else
  2269. ths_eot = 4;
  2270. ddr_clk_pre = DIV_ROUND_UP(tclk_pre + tlpx + tclk_zero + tclk_prepare,
  2271. 4);
  2272. ddr_clk_post = DIV_ROUND_UP(tclk_post + ths_trail, 4) + ths_eot;
  2273. BUG_ON(ddr_clk_pre == 0 || ddr_clk_pre > 255);
  2274. BUG_ON(ddr_clk_post == 0 || ddr_clk_post > 255);
  2275. r = dsi_read_reg(DSI_CLK_TIMING);
  2276. r = FLD_MOD(r, ddr_clk_pre, 15, 8);
  2277. r = FLD_MOD(r, ddr_clk_post, 7, 0);
  2278. dsi_write_reg(DSI_CLK_TIMING, r);
  2279. DSSDBG("ddr_clk_pre %u, ddr_clk_post %u\n",
  2280. ddr_clk_pre,
  2281. ddr_clk_post);
  2282. enter_hs_mode_lat = 1 + DIV_ROUND_UP(tlpx, 4) +
  2283. DIV_ROUND_UP(ths_prepare, 4) +
  2284. DIV_ROUND_UP(ths_zero + 3, 4);
  2285. exit_hs_mode_lat = DIV_ROUND_UP(ths_trail + ths_exit, 4) + 1 + ths_eot;
  2286. r = FLD_VAL(enter_hs_mode_lat, 31, 16) |
  2287. FLD_VAL(exit_hs_mode_lat, 15, 0);
  2288. dsi_write_reg(DSI_VM_TIMING7, r);
  2289. DSSDBG("enter_hs_mode_lat %u, exit_hs_mode_lat %u\n",
  2290. enter_hs_mode_lat, exit_hs_mode_lat);
  2291. }
  2292. #define DSI_DECL_VARS \
  2293. int __dsi_cb = 0; u32 __dsi_cv = 0;
  2294. #define DSI_FLUSH(ch) \
  2295. if (__dsi_cb > 0) { \
  2296. /*DSSDBG("sending long packet %#010x\n", __dsi_cv);*/ \
  2297. dsi_write_reg(DSI_VC_LONG_PACKET_PAYLOAD(ch), __dsi_cv); \
  2298. __dsi_cb = __dsi_cv = 0; \
  2299. }
  2300. #define DSI_PUSH(ch, data) \
  2301. do { \
  2302. __dsi_cv |= (data) << (__dsi_cb * 8); \
  2303. /*DSSDBG("cv = %#010x, cb = %d\n", __dsi_cv, __dsi_cb);*/ \
  2304. if (++__dsi_cb > 3) \
  2305. DSI_FLUSH(ch); \
  2306. } while (0)
  2307. static int dsi_update_screen_l4(struct omap_dss_device *dssdev,
  2308. int x, int y, int w, int h)
  2309. {
  2310. /* Note: supports only 24bit colors in 32bit container */
  2311. int first = 1;
  2312. int fifo_stalls = 0;
  2313. int max_dsi_packet_size;
  2314. int max_data_per_packet;
  2315. int max_pixels_per_packet;
  2316. int pixels_left;
  2317. int bytespp = dssdev->ctrl.pixel_size / 8;
  2318. int scr_width;
  2319. u32 __iomem *data;
  2320. int start_offset;
  2321. int horiz_inc;
  2322. int current_x;
  2323. struct omap_overlay *ovl;
  2324. debug_irq = 0;
  2325. DSSDBG("dsi_update_screen_l4 (%d,%d %dx%d)\n",
  2326. x, y, w, h);
  2327. ovl = dssdev->manager->overlays[0];
  2328. if (ovl->info.color_mode != OMAP_DSS_COLOR_RGB24U)
  2329. return -EINVAL;
  2330. if (dssdev->ctrl.pixel_size != 24)
  2331. return -EINVAL;
  2332. scr_width = ovl->info.screen_width;
  2333. data = ovl->info.vaddr;
  2334. start_offset = scr_width * y + x;
  2335. horiz_inc = scr_width - w;
  2336. current_x = x;
  2337. /* We need header(4) + DCSCMD(1) + pixels(numpix*bytespp) bytes
  2338. * in fifo */
  2339. /* When using CPU, max long packet size is TX buffer size */
  2340. max_dsi_packet_size = dsi.vc[0].fifo_size * 32 * 4;
  2341. /* we seem to get better perf if we divide the tx fifo to half,
  2342. and while the other half is being sent, we fill the other half
  2343. max_dsi_packet_size /= 2; */
  2344. max_data_per_packet = max_dsi_packet_size - 4 - 1;
  2345. max_pixels_per_packet = max_data_per_packet / bytespp;
  2346. DSSDBG("max_pixels_per_packet %d\n", max_pixels_per_packet);
  2347. pixels_left = w * h;
  2348. DSSDBG("total pixels %d\n", pixels_left);
  2349. data += start_offset;
  2350. while (pixels_left > 0) {
  2351. /* 0x2c = write_memory_start */
  2352. /* 0x3c = write_memory_continue */
  2353. u8 dcs_cmd = first ? 0x2c : 0x3c;
  2354. int pixels;
  2355. DSI_DECL_VARS;
  2356. first = 0;
  2357. #if 1
  2358. /* using fifo not empty */
  2359. /* TX_FIFO_NOT_EMPTY */
  2360. while (FLD_GET(dsi_read_reg(DSI_VC_CTRL(0)), 5, 5)) {
  2361. fifo_stalls++;
  2362. if (fifo_stalls > 0xfffff) {
  2363. DSSERR("fifo stalls overflow, pixels left %d\n",
  2364. pixels_left);
  2365. dsi_if_enable(0);
  2366. return -EIO;
  2367. }
  2368. udelay(1);
  2369. }
  2370. #elif 1
  2371. /* using fifo emptiness */
  2372. while ((REG_GET(DSI_TX_FIFO_VC_EMPTINESS, 7, 0)+1)*4 <
  2373. max_dsi_packet_size) {
  2374. fifo_stalls++;
  2375. if (fifo_stalls > 0xfffff) {
  2376. DSSERR("fifo stalls overflow, pixels left %d\n",
  2377. pixels_left);
  2378. dsi_if_enable(0);
  2379. return -EIO;
  2380. }
  2381. }
  2382. #else
  2383. while ((REG_GET(DSI_TX_FIFO_VC_EMPTINESS, 7, 0)+1)*4 == 0) {
  2384. fifo_stalls++;
  2385. if (fifo_stalls > 0xfffff) {
  2386. DSSERR("fifo stalls overflow, pixels left %d\n",
  2387. pixels_left);
  2388. dsi_if_enable(0);
  2389. return -EIO;
  2390. }
  2391. }
  2392. #endif
  2393. pixels = min(max_pixels_per_packet, pixels_left);
  2394. pixels_left -= pixels;
  2395. dsi_vc_write_long_header(0, DSI_DT_DCS_LONG_WRITE,
  2396. 1 + pixels * bytespp, 0);
  2397. DSI_PUSH(0, dcs_cmd);
  2398. while (pixels-- > 0) {
  2399. u32 pix = __raw_readl(data++);
  2400. DSI_PUSH(0, (pix >> 16) & 0xff);
  2401. DSI_PUSH(0, (pix >> 8) & 0xff);
  2402. DSI_PUSH(0, (pix >> 0) & 0xff);
  2403. current_x++;
  2404. if (current_x == x+w) {
  2405. current_x = x;
  2406. data += horiz_inc;
  2407. }
  2408. }
  2409. DSI_FLUSH(0);
  2410. }
  2411. return 0;
  2412. }
  2413. static void dsi_update_screen_dispc(struct omap_dss_device *dssdev,
  2414. u16 x, u16 y, u16 w, u16 h)
  2415. {
  2416. unsigned bytespp;
  2417. unsigned bytespl;
  2418. unsigned bytespf;
  2419. unsigned total_len;
  2420. unsigned packet_payload;
  2421. unsigned packet_len;
  2422. u32 l;
  2423. int r;
  2424. const unsigned channel = dsi.update_channel;
  2425. /* line buffer is 1024 x 24bits */
  2426. /* XXX: for some reason using full buffer size causes considerable TX
  2427. * slowdown with update sizes that fill the whole buffer */
  2428. const unsigned line_buf_size = 1023 * 3;
  2429. DSSDBG("dsi_update_screen_dispc(%d,%d %dx%d)\n",
  2430. x, y, w, h);
  2431. dsi_vc_config_vp(channel);
  2432. bytespp = dssdev->ctrl.pixel_size / 8;
  2433. bytespl = w * bytespp;
  2434. bytespf = bytespl * h;
  2435. /* NOTE: packet_payload has to be equal to N * bytespl, where N is
  2436. * number of lines in a packet. See errata about VP_CLK_RATIO */
  2437. if (bytespf < line_buf_size)
  2438. packet_payload = bytespf;
  2439. else
  2440. packet_payload = (line_buf_size) / bytespl * bytespl;
  2441. packet_len = packet_payload + 1; /* 1 byte for DCS cmd */
  2442. total_len = (bytespf / packet_payload) * packet_len;
  2443. if (bytespf % packet_payload)
  2444. total_len += (bytespf % packet_payload) + 1;
  2445. l = FLD_VAL(total_len, 23, 0); /* TE_SIZE */
  2446. dsi_write_reg(DSI_VC_TE(channel), l);
  2447. dsi_vc_write_long_header(channel, DSI_DT_DCS_LONG_WRITE, packet_len, 0);
  2448. if (dsi.te_enabled)
  2449. l = FLD_MOD(l, 1, 30, 30); /* TE_EN */
  2450. else
  2451. l = FLD_MOD(l, 1, 31, 31); /* TE_START */
  2452. dsi_write_reg(DSI_VC_TE(channel), l);
  2453. /* We put SIDLEMODE to no-idle for the duration of the transfer,
  2454. * because DSS interrupts are not capable of waking up the CPU and the
  2455. * framedone interrupt could be delayed for quite a long time. I think
  2456. * the same goes for any DSS interrupts, but for some reason I have not
  2457. * seen the problem anywhere else than here.
  2458. */
  2459. dispc_disable_sidle();
  2460. dsi_perf_mark_start();
  2461. r = queue_delayed_work(dsi.workqueue, &dsi.framedone_timeout_work,
  2462. msecs_to_jiffies(250));
  2463. BUG_ON(r == 0);
  2464. dss_start_update(dssdev);
  2465. if (dsi.te_enabled) {
  2466. /* disable LP_RX_TO, so that we can receive TE. Time to wait
  2467. * for TE is longer than the timer allows */
  2468. REG_FLD_MOD(DSI_TIMING2, 0, 15, 15); /* LP_RX_TO */
  2469. dsi_vc_send_bta(channel);
  2470. #ifdef DSI_CATCH_MISSING_TE
  2471. mod_timer(&dsi.te_timer, jiffies + msecs_to_jiffies(250));
  2472. #endif
  2473. }
  2474. }
  2475. #ifdef DSI_CATCH_MISSING_TE
  2476. static void dsi_te_timeout(unsigned long arg)
  2477. {
  2478. DSSERR("TE not received for 250ms!\n");
  2479. }
  2480. #endif
  2481. static void dsi_framedone_bta_callback(void *data, u32 mask);
  2482. static void dsi_handle_framedone(int error)
  2483. {
  2484. const int channel = dsi.update_channel;
  2485. dsi_unregister_isr_vc(channel, dsi_framedone_bta_callback,
  2486. NULL, DSI_VC_IRQ_BTA);
  2487. cancel_delayed_work(&dsi.framedone_timeout_work);
  2488. /* SIDLEMODE back to smart-idle */
  2489. dispc_enable_sidle();
  2490. if (dsi.te_enabled) {
  2491. /* enable LP_RX_TO again after the TE */
  2492. REG_FLD_MOD(DSI_TIMING2, 1, 15, 15); /* LP_RX_TO */
  2493. }
  2494. /* RX_FIFO_NOT_EMPTY */
  2495. if (REG_GET(DSI_VC_CTRL(channel), 20, 20)) {
  2496. DSSERR("Received error during frame transfer:\n");
  2497. dsi_vc_flush_receive_data(channel);
  2498. if (!error)
  2499. error = -EIO;
  2500. }
  2501. dsi.framedone_callback(error, dsi.framedone_data);
  2502. if (!error)
  2503. dsi_perf_show("DISPC");
  2504. }
  2505. static void dsi_framedone_timeout_work_callback(struct work_struct *work)
  2506. {
  2507. /* XXX While extremely unlikely, we could get FRAMEDONE interrupt after
  2508. * 250ms which would conflict with this timeout work. What should be
  2509. * done is first cancel the transfer on the HW, and then cancel the
  2510. * possibly scheduled framedone work. However, cancelling the transfer
  2511. * on the HW is buggy, and would probably require resetting the whole
  2512. * DSI */
  2513. DSSERR("Framedone not received for 250ms!\n");
  2514. dsi_handle_framedone(-ETIMEDOUT);
  2515. }
  2516. static void dsi_framedone_bta_callback(void *data, u32 mask)
  2517. {
  2518. dsi_handle_framedone(0);
  2519. #ifdef CONFIG_OMAP2_DSS_FAKE_VSYNC
  2520. dispc_fake_vsync_irq();
  2521. #endif
  2522. }
  2523. static void dsi_framedone_irq_callback(void *data, u32 mask)
  2524. {
  2525. const int channel = dsi.update_channel;
  2526. int r;
  2527. /* Note: We get FRAMEDONE when DISPC has finished sending pixels and
  2528. * turns itself off. However, DSI still has the pixels in its buffers,
  2529. * and is sending the data.
  2530. */
  2531. if (dsi.te_enabled) {
  2532. /* enable LP_RX_TO again after the TE */
  2533. REG_FLD_MOD(DSI_TIMING2, 1, 15, 15); /* LP_RX_TO */
  2534. }
  2535. /* Send BTA after the frame. We need this for the TE to work, as TE
  2536. * trigger is only sent for BTAs without preceding packet. Thus we need
  2537. * to BTA after the pixel packets so that next BTA will cause TE
  2538. * trigger.
  2539. *
  2540. * This is not needed when TE is not in use, but we do it anyway to
  2541. * make sure that the transfer has been completed. It would be more
  2542. * optimal, but more complex, to wait only just before starting next
  2543. * transfer.
  2544. *
  2545. * Also, as there's no interrupt telling when the transfer has been
  2546. * done and the channel could be reconfigured, the only way is to
  2547. * busyloop until TE_SIZE is zero. With BTA we can do this
  2548. * asynchronously.
  2549. * */
  2550. r = dsi_register_isr_vc(channel, dsi_framedone_bta_callback,
  2551. NULL, DSI_VC_IRQ_BTA);
  2552. if (r) {
  2553. DSSERR("Failed to register BTA ISR\n");
  2554. dsi_handle_framedone(-EIO);
  2555. return;
  2556. }
  2557. r = dsi_vc_send_bta(channel);
  2558. if (r) {
  2559. DSSERR("BTA after framedone failed\n");
  2560. dsi_unregister_isr_vc(channel, dsi_framedone_bta_callback,
  2561. NULL, DSI_VC_IRQ_BTA);
  2562. dsi_handle_framedone(-EIO);
  2563. }
  2564. }
  2565. int omap_dsi_prepare_update(struct omap_dss_device *dssdev,
  2566. u16 *x, u16 *y, u16 *w, u16 *h,
  2567. bool enlarge_update_area)
  2568. {
  2569. u16 dw, dh;
  2570. dssdev->driver->get_resolution(dssdev, &dw, &dh);
  2571. if (*x > dw || *y > dh)
  2572. return -EINVAL;
  2573. if (*x + *w > dw)
  2574. return -EINVAL;
  2575. if (*y + *h > dh)
  2576. return -EINVAL;
  2577. if (*w == 1)
  2578. return -EINVAL;
  2579. if (*w == 0 || *h == 0)
  2580. return -EINVAL;
  2581. dsi_perf_mark_setup();
  2582. if (dssdev->manager->caps & OMAP_DSS_OVL_MGR_CAP_DISPC) {
  2583. dss_setup_partial_planes(dssdev, x, y, w, h,
  2584. enlarge_update_area);
  2585. dispc_set_lcd_size(dssdev->manager->id, *w, *h);
  2586. }
  2587. return 0;
  2588. }
  2589. EXPORT_SYMBOL(omap_dsi_prepare_update);
  2590. int omap_dsi_update(struct omap_dss_device *dssdev,
  2591. int channel,
  2592. u16 x, u16 y, u16 w, u16 h,
  2593. void (*callback)(int, void *), void *data)
  2594. {
  2595. dsi.update_channel = channel;
  2596. /* OMAP DSS cannot send updates of odd widths.
  2597. * omap_dsi_prepare_update() makes the widths even, but add a BUG_ON
  2598. * here to make sure we catch erroneous updates. Otherwise we'll only
  2599. * see rather obscure HW error happening, as DSS halts. */
  2600. BUG_ON(x % 2 == 1);
  2601. if (dssdev->manager->caps & OMAP_DSS_OVL_MGR_CAP_DISPC) {
  2602. dsi.framedone_callback = callback;
  2603. dsi.framedone_data = data;
  2604. dsi.update_region.x = x;
  2605. dsi.update_region.y = y;
  2606. dsi.update_region.w = w;
  2607. dsi.update_region.h = h;
  2608. dsi.update_region.device = dssdev;
  2609. dsi_update_screen_dispc(dssdev, x, y, w, h);
  2610. } else {
  2611. int r;
  2612. r = dsi_update_screen_l4(dssdev, x, y, w, h);
  2613. if (r)
  2614. return r;
  2615. dsi_perf_show("L4");
  2616. callback(0, data);
  2617. }
  2618. return 0;
  2619. }
  2620. EXPORT_SYMBOL(omap_dsi_update);
  2621. /* Display funcs */
  2622. static int dsi_display_init_dispc(struct omap_dss_device *dssdev)
  2623. {
  2624. int r;
  2625. r = omap_dispc_register_isr(dsi_framedone_irq_callback, NULL,
  2626. DISPC_IRQ_FRAMEDONE);
  2627. if (r) {
  2628. DSSERR("can't get FRAMEDONE irq\n");
  2629. return r;
  2630. }
  2631. dispc_set_lcd_display_type(dssdev->manager->id,
  2632. OMAP_DSS_LCD_DISPLAY_TFT);
  2633. dispc_set_parallel_interface_mode(dssdev->manager->id,
  2634. OMAP_DSS_PARALLELMODE_DSI);
  2635. dispc_enable_fifohandcheck(dssdev->manager->id, 1);
  2636. dispc_set_tft_data_lines(dssdev->manager->id, dssdev->ctrl.pixel_size);
  2637. {
  2638. struct omap_video_timings timings = {
  2639. .hsw = 1,
  2640. .hfp = 1,
  2641. .hbp = 1,
  2642. .vsw = 1,
  2643. .vfp = 0,
  2644. .vbp = 0,
  2645. };
  2646. dispc_set_lcd_timings(dssdev->manager->id, &timings);
  2647. }
  2648. return 0;
  2649. }
  2650. static void dsi_display_uninit_dispc(struct omap_dss_device *dssdev)
  2651. {
  2652. omap_dispc_unregister_isr(dsi_framedone_irq_callback, NULL,
  2653. DISPC_IRQ_FRAMEDONE);
  2654. }
  2655. static int dsi_configure_dsi_clocks(struct omap_dss_device *dssdev)
  2656. {
  2657. struct dsi_clock_info cinfo;
  2658. int r;
  2659. /* we always use DSS_CLK_SYSCK as input clock */
  2660. cinfo.use_sys_clk = true;
  2661. cinfo.regn = dssdev->phy.dsi.div.regn;
  2662. cinfo.regm = dssdev->phy.dsi.div.regm;
  2663. cinfo.regm_dispc = dssdev->phy.dsi.div.regm_dispc;
  2664. cinfo.regm_dsi = dssdev->phy.dsi.div.regm_dsi;
  2665. r = dsi_calc_clock_rates(dssdev, &cinfo);
  2666. if (r) {
  2667. DSSERR("Failed to calc dsi clocks\n");
  2668. return r;
  2669. }
  2670. r = dsi_pll_set_clock_div(&cinfo);
  2671. if (r) {
  2672. DSSERR("Failed to set dsi clocks\n");
  2673. return r;
  2674. }
  2675. return 0;
  2676. }
  2677. static int dsi_configure_dispc_clocks(struct omap_dss_device *dssdev)
  2678. {
  2679. struct dispc_clock_info dispc_cinfo;
  2680. int r;
  2681. unsigned long long fck;
  2682. fck = dsi_get_pll_hsdiv_dispc_rate();
  2683. dispc_cinfo.lck_div = dssdev->phy.dsi.div.lck_div;
  2684. dispc_cinfo.pck_div = dssdev->phy.dsi.div.pck_div;
  2685. r = dispc_calc_clock_rates(fck, &dispc_cinfo);
  2686. if (r) {
  2687. DSSERR("Failed to calc dispc clocks\n");
  2688. return r;
  2689. }
  2690. r = dispc_set_clock_div(dssdev->manager->id, &dispc_cinfo);
  2691. if (r) {
  2692. DSSERR("Failed to set dispc clocks\n");
  2693. return r;
  2694. }
  2695. return 0;
  2696. }
  2697. static int dsi_display_init_dsi(struct omap_dss_device *dssdev)
  2698. {
  2699. int r;
  2700. _dsi_print_reset_status();
  2701. r = dsi_pll_init(dssdev, true, true);
  2702. if (r)
  2703. goto err0;
  2704. r = dsi_configure_dsi_clocks(dssdev);
  2705. if (r)
  2706. goto err1;
  2707. dss_select_dispc_clk_source(DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC);
  2708. dss_select_dsi_clk_source(DSS_CLK_SRC_DSI_PLL_HSDIV_DSI);
  2709. DSSDBG("PLL OK\n");
  2710. r = dsi_configure_dispc_clocks(dssdev);
  2711. if (r)
  2712. goto err2;
  2713. r = dsi_complexio_init(dssdev);
  2714. if (r)
  2715. goto err2;
  2716. _dsi_print_reset_status();
  2717. dsi_proto_timings(dssdev);
  2718. dsi_set_lp_clk_divisor(dssdev);
  2719. if (1)
  2720. _dsi_print_reset_status();
  2721. r = dsi_proto_config(dssdev);
  2722. if (r)
  2723. goto err3;
  2724. /* enable interface */
  2725. dsi_vc_enable(0, 1);
  2726. dsi_vc_enable(1, 1);
  2727. dsi_vc_enable(2, 1);
  2728. dsi_vc_enable(3, 1);
  2729. dsi_if_enable(1);
  2730. dsi_force_tx_stop_mode_io();
  2731. return 0;
  2732. err3:
  2733. dsi_complexio_uninit();
  2734. err2:
  2735. dss_select_dispc_clk_source(DSS_CLK_SRC_FCK);
  2736. dss_select_dsi_clk_source(DSS_CLK_SRC_FCK);
  2737. err1:
  2738. dsi_pll_uninit();
  2739. err0:
  2740. return r;
  2741. }
  2742. static void dsi_display_uninit_dsi(struct omap_dss_device *dssdev)
  2743. {
  2744. /* disable interface */
  2745. dsi_if_enable(0);
  2746. dsi_vc_enable(0, 0);
  2747. dsi_vc_enable(1, 0);
  2748. dsi_vc_enable(2, 0);
  2749. dsi_vc_enable(3, 0);
  2750. dss_select_dispc_clk_source(DSS_CLK_SRC_FCK);
  2751. dss_select_dsi_clk_source(DSS_CLK_SRC_FCK);
  2752. dsi_complexio_uninit();
  2753. dsi_pll_uninit();
  2754. }
  2755. static int dsi_core_init(void)
  2756. {
  2757. /* Autoidle */
  2758. REG_FLD_MOD(DSI_SYSCONFIG, 1, 0, 0);
  2759. /* ENWAKEUP */
  2760. REG_FLD_MOD(DSI_SYSCONFIG, 1, 2, 2);
  2761. /* SIDLEMODE smart-idle */
  2762. REG_FLD_MOD(DSI_SYSCONFIG, 2, 4, 3);
  2763. _dsi_initialize_irq();
  2764. return 0;
  2765. }
  2766. int omapdss_dsi_display_enable(struct omap_dss_device *dssdev)
  2767. {
  2768. int r = 0;
  2769. DSSDBG("dsi_display_enable\n");
  2770. WARN_ON(!dsi_bus_is_locked());
  2771. mutex_lock(&dsi.lock);
  2772. r = omap_dss_start_device(dssdev);
  2773. if (r) {
  2774. DSSERR("failed to start device\n");
  2775. goto err0;
  2776. }
  2777. enable_clocks(1);
  2778. dsi_enable_pll_clock(1);
  2779. r = _dsi_reset();
  2780. if (r)
  2781. goto err1;
  2782. dsi_core_init();
  2783. r = dsi_display_init_dispc(dssdev);
  2784. if (r)
  2785. goto err1;
  2786. r = dsi_display_init_dsi(dssdev);
  2787. if (r)
  2788. goto err2;
  2789. mutex_unlock(&dsi.lock);
  2790. return 0;
  2791. err2:
  2792. dsi_display_uninit_dispc(dssdev);
  2793. err1:
  2794. enable_clocks(0);
  2795. dsi_enable_pll_clock(0);
  2796. omap_dss_stop_device(dssdev);
  2797. err0:
  2798. mutex_unlock(&dsi.lock);
  2799. DSSDBG("dsi_display_enable FAILED\n");
  2800. return r;
  2801. }
  2802. EXPORT_SYMBOL(omapdss_dsi_display_enable);
  2803. void omapdss_dsi_display_disable(struct omap_dss_device *dssdev)
  2804. {
  2805. DSSDBG("dsi_display_disable\n");
  2806. WARN_ON(!dsi_bus_is_locked());
  2807. mutex_lock(&dsi.lock);
  2808. dsi_display_uninit_dispc(dssdev);
  2809. dsi_display_uninit_dsi(dssdev);
  2810. enable_clocks(0);
  2811. dsi_enable_pll_clock(0);
  2812. omap_dss_stop_device(dssdev);
  2813. mutex_unlock(&dsi.lock);
  2814. }
  2815. EXPORT_SYMBOL(omapdss_dsi_display_disable);
  2816. int omapdss_dsi_enable_te(struct omap_dss_device *dssdev, bool enable)
  2817. {
  2818. dsi.te_enabled = enable;
  2819. return 0;
  2820. }
  2821. EXPORT_SYMBOL(omapdss_dsi_enable_te);
  2822. void dsi_get_overlay_fifo_thresholds(enum omap_plane plane,
  2823. u32 fifo_size, enum omap_burst_size *burst_size,
  2824. u32 *fifo_low, u32 *fifo_high)
  2825. {
  2826. unsigned burst_size_bytes;
  2827. *burst_size = OMAP_DSS_BURST_16x32;
  2828. burst_size_bytes = 16 * 32 / 8;
  2829. *fifo_high = fifo_size - burst_size_bytes;
  2830. *fifo_low = fifo_size - burst_size_bytes * 2;
  2831. }
  2832. int dsi_init_display(struct omap_dss_device *dssdev)
  2833. {
  2834. DSSDBG("DSI init\n");
  2835. /* XXX these should be figured out dynamically */
  2836. dssdev->caps = OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE |
  2837. OMAP_DSS_DISPLAY_CAP_TEAR_ELIM;
  2838. if (dsi.vdds_dsi_reg == NULL) {
  2839. struct regulator *vdds_dsi;
  2840. vdds_dsi = regulator_get(&dsi.pdev->dev, "vdds_dsi");
  2841. if (IS_ERR(vdds_dsi)) {
  2842. DSSERR("can't get VDDS_DSI regulator\n");
  2843. return PTR_ERR(vdds_dsi);
  2844. }
  2845. dsi.vdds_dsi_reg = vdds_dsi;
  2846. }
  2847. return 0;
  2848. }
  2849. int omap_dsi_request_vc(struct omap_dss_device *dssdev, int *channel)
  2850. {
  2851. int i;
  2852. for (i = 0; i < ARRAY_SIZE(dsi.vc); i++) {
  2853. if (!dsi.vc[i].dssdev) {
  2854. dsi.vc[i].dssdev = dssdev;
  2855. *channel = i;
  2856. return 0;
  2857. }
  2858. }
  2859. DSSERR("cannot get VC for display %s", dssdev->name);
  2860. return -ENOSPC;
  2861. }
  2862. EXPORT_SYMBOL(omap_dsi_request_vc);
  2863. int omap_dsi_set_vc_id(struct omap_dss_device *dssdev, int channel, int vc_id)
  2864. {
  2865. if (vc_id < 0 || vc_id > 3) {
  2866. DSSERR("VC ID out of range\n");
  2867. return -EINVAL;
  2868. }
  2869. if (channel < 0 || channel > 3) {
  2870. DSSERR("Virtual Channel out of range\n");
  2871. return -EINVAL;
  2872. }
  2873. if (dsi.vc[channel].dssdev != dssdev) {
  2874. DSSERR("Virtual Channel not allocated to display %s\n",
  2875. dssdev->name);
  2876. return -EINVAL;
  2877. }
  2878. dsi.vc[channel].vc_id = vc_id;
  2879. return 0;
  2880. }
  2881. EXPORT_SYMBOL(omap_dsi_set_vc_id);
  2882. void omap_dsi_release_vc(struct omap_dss_device *dssdev, int channel)
  2883. {
  2884. if ((channel >= 0 && channel <= 3) &&
  2885. dsi.vc[channel].dssdev == dssdev) {
  2886. dsi.vc[channel].dssdev = NULL;
  2887. dsi.vc[channel].vc_id = 0;
  2888. }
  2889. }
  2890. EXPORT_SYMBOL(omap_dsi_release_vc);
  2891. void dsi_wait_pll_hsdiv_dispc_active(void)
  2892. {
  2893. if (wait_for_bit_change(DSI_PLL_STATUS, 7, 1) != 1)
  2894. DSSERR("%s (%s) not active\n",
  2895. dss_get_generic_clk_source_name(DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC),
  2896. dss_feat_get_clk_source_name(DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC));
  2897. }
  2898. void dsi_wait_pll_hsdiv_dsi_active(void)
  2899. {
  2900. if (wait_for_bit_change(DSI_PLL_STATUS, 8, 1) != 1)
  2901. DSSERR("%s (%s) not active\n",
  2902. dss_get_generic_clk_source_name(DSS_CLK_SRC_DSI_PLL_HSDIV_DSI),
  2903. dss_feat_get_clk_source_name(DSS_CLK_SRC_DSI_PLL_HSDIV_DSI));
  2904. }
  2905. static void dsi_calc_clock_param_ranges(void)
  2906. {
  2907. dsi.regn_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGN);
  2908. dsi.regm_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM);
  2909. dsi.regm_dispc_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM_DISPC);
  2910. dsi.regm_dsi_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM_DSI);
  2911. dsi.fint_min = dss_feat_get_param_min(FEAT_PARAM_DSIPLL_FINT);
  2912. dsi.fint_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_FINT);
  2913. dsi.lpdiv_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_LPDIV);
  2914. }
  2915. static int dsi_init(struct platform_device *pdev)
  2916. {
  2917. u32 rev;
  2918. int r, i;
  2919. struct resource *dsi_mem;
  2920. spin_lock_init(&dsi.irq_lock);
  2921. spin_lock_init(&dsi.errors_lock);
  2922. dsi.errors = 0;
  2923. #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
  2924. spin_lock_init(&dsi.irq_stats_lock);
  2925. dsi.irq_stats.last_reset = jiffies;
  2926. #endif
  2927. mutex_init(&dsi.lock);
  2928. sema_init(&dsi.bus_lock, 1);
  2929. dsi.workqueue = create_singlethread_workqueue("dsi");
  2930. if (dsi.workqueue == NULL)
  2931. return -ENOMEM;
  2932. INIT_DELAYED_WORK_DEFERRABLE(&dsi.framedone_timeout_work,
  2933. dsi_framedone_timeout_work_callback);
  2934. #ifdef DSI_CATCH_MISSING_TE
  2935. init_timer(&dsi.te_timer);
  2936. dsi.te_timer.function = dsi_te_timeout;
  2937. dsi.te_timer.data = 0;
  2938. #endif
  2939. dsi_mem = platform_get_resource(dsi.pdev, IORESOURCE_MEM, 0);
  2940. if (!dsi_mem) {
  2941. DSSERR("can't get IORESOURCE_MEM DSI\n");
  2942. r = -EINVAL;
  2943. goto err1;
  2944. }
  2945. dsi.base = ioremap(dsi_mem->start, resource_size(dsi_mem));
  2946. if (!dsi.base) {
  2947. DSSERR("can't ioremap DSI\n");
  2948. r = -ENOMEM;
  2949. goto err1;
  2950. }
  2951. dsi.irq = platform_get_irq(dsi.pdev, 0);
  2952. if (dsi.irq < 0) {
  2953. DSSERR("platform_get_irq failed\n");
  2954. r = -ENODEV;
  2955. goto err2;
  2956. }
  2957. r = request_irq(dsi.irq, omap_dsi_irq_handler, IRQF_SHARED,
  2958. "OMAP DSI1", dsi.pdev);
  2959. if (r < 0) {
  2960. DSSERR("request_irq failed\n");
  2961. goto err2;
  2962. }
  2963. /* DSI VCs initialization */
  2964. for (i = 0; i < ARRAY_SIZE(dsi.vc); i++) {
  2965. dsi.vc[i].mode = DSI_VC_MODE_L4;
  2966. dsi.vc[i].dssdev = NULL;
  2967. dsi.vc[i].vc_id = 0;
  2968. }
  2969. dsi_calc_clock_param_ranges();
  2970. enable_clocks(1);
  2971. rev = dsi_read_reg(DSI_REVISION);
  2972. dev_dbg(&pdev->dev, "OMAP DSI rev %d.%d\n",
  2973. FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
  2974. enable_clocks(0);
  2975. return 0;
  2976. err2:
  2977. iounmap(dsi.base);
  2978. err1:
  2979. destroy_workqueue(dsi.workqueue);
  2980. return r;
  2981. }
  2982. static void dsi_exit(void)
  2983. {
  2984. if (dsi.vdds_dsi_reg != NULL) {
  2985. regulator_put(dsi.vdds_dsi_reg);
  2986. dsi.vdds_dsi_reg = NULL;
  2987. }
  2988. free_irq(dsi.irq, dsi.pdev);
  2989. iounmap(dsi.base);
  2990. destroy_workqueue(dsi.workqueue);
  2991. DSSDBG("omap_dsi_exit\n");
  2992. }
  2993. /* DSI1 HW IP initialisation */
  2994. static int omap_dsi1hw_probe(struct platform_device *pdev)
  2995. {
  2996. int r;
  2997. dsi.pdev = pdev;
  2998. r = dsi_init(pdev);
  2999. if (r) {
  3000. DSSERR("Failed to initialize DSI\n");
  3001. goto err_dsi;
  3002. }
  3003. err_dsi:
  3004. return r;
  3005. }
  3006. static int omap_dsi1hw_remove(struct platform_device *pdev)
  3007. {
  3008. dsi_exit();
  3009. return 0;
  3010. }
  3011. static struct platform_driver omap_dsi1hw_driver = {
  3012. .probe = omap_dsi1hw_probe,
  3013. .remove = omap_dsi1hw_remove,
  3014. .driver = {
  3015. .name = "omapdss_dsi1",
  3016. .owner = THIS_MODULE,
  3017. },
  3018. };
  3019. int dsi_init_platform_driver(void)
  3020. {
  3021. return platform_driver_register(&omap_dsi1hw_driver);
  3022. }
  3023. void dsi_uninit_platform_driver(void)
  3024. {
  3025. return platform_driver_unregister(&omap_dsi1hw_driver);
  3026. }