dsi.c 76 KB

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