dsi.c 87 KB

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