dsi.c 87 KB

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