dsi.c 77 KB

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