dsi.c 83 KB

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