dsi.c 86 KB

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