dsi.c 77 KB

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