dsi.c 86 KB

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