dsi.c 86 KB

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