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