dsi.c 82 KB

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