dsi.c 86 KB

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