dsi.c 76 KB

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