dsi.c 95 KB

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