dsi.c 111 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469
  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 <linux/sched.h>
  35. #include <linux/slab.h>
  36. #include <linux/debugfs.h>
  37. #include <linux/pm_runtime.h>
  38. #include <video/omapdss.h>
  39. #include <video/mipi_display.h>
  40. #include <plat/clock.h>
  41. #include "dss.h"
  42. #include "dss_features.h"
  43. /*#define VERBOSE_IRQ*/
  44. #define DSI_CATCH_MISSING_TE
  45. struct dsi_reg { u16 idx; };
  46. #define DSI_REG(idx) ((const struct dsi_reg) { idx })
  47. #define DSI_SZ_REGS SZ_1K
  48. /* DSI Protocol Engine */
  49. #define DSI_REVISION DSI_REG(0x0000)
  50. #define DSI_SYSCONFIG DSI_REG(0x0010)
  51. #define DSI_SYSSTATUS DSI_REG(0x0014)
  52. #define DSI_IRQSTATUS DSI_REG(0x0018)
  53. #define DSI_IRQENABLE DSI_REG(0x001C)
  54. #define DSI_CTRL DSI_REG(0x0040)
  55. #define DSI_GNQ DSI_REG(0x0044)
  56. #define DSI_COMPLEXIO_CFG1 DSI_REG(0x0048)
  57. #define DSI_COMPLEXIO_IRQ_STATUS DSI_REG(0x004C)
  58. #define DSI_COMPLEXIO_IRQ_ENABLE DSI_REG(0x0050)
  59. #define DSI_CLK_CTRL DSI_REG(0x0054)
  60. #define DSI_TIMING1 DSI_REG(0x0058)
  61. #define DSI_TIMING2 DSI_REG(0x005C)
  62. #define DSI_VM_TIMING1 DSI_REG(0x0060)
  63. #define DSI_VM_TIMING2 DSI_REG(0x0064)
  64. #define DSI_VM_TIMING3 DSI_REG(0x0068)
  65. #define DSI_CLK_TIMING DSI_REG(0x006C)
  66. #define DSI_TX_FIFO_VC_SIZE DSI_REG(0x0070)
  67. #define DSI_RX_FIFO_VC_SIZE DSI_REG(0x0074)
  68. #define DSI_COMPLEXIO_CFG2 DSI_REG(0x0078)
  69. #define DSI_RX_FIFO_VC_FULLNESS DSI_REG(0x007C)
  70. #define DSI_VM_TIMING4 DSI_REG(0x0080)
  71. #define DSI_TX_FIFO_VC_EMPTINESS DSI_REG(0x0084)
  72. #define DSI_VM_TIMING5 DSI_REG(0x0088)
  73. #define DSI_VM_TIMING6 DSI_REG(0x008C)
  74. #define DSI_VM_TIMING7 DSI_REG(0x0090)
  75. #define DSI_STOPCLK_TIMING DSI_REG(0x0094)
  76. #define DSI_VC_CTRL(n) DSI_REG(0x0100 + (n * 0x20))
  77. #define DSI_VC_TE(n) DSI_REG(0x0104 + (n * 0x20))
  78. #define DSI_VC_LONG_PACKET_HEADER(n) DSI_REG(0x0108 + (n * 0x20))
  79. #define DSI_VC_LONG_PACKET_PAYLOAD(n) DSI_REG(0x010C + (n * 0x20))
  80. #define DSI_VC_SHORT_PACKET_HEADER(n) DSI_REG(0x0110 + (n * 0x20))
  81. #define DSI_VC_IRQSTATUS(n) DSI_REG(0x0118 + (n * 0x20))
  82. #define DSI_VC_IRQENABLE(n) DSI_REG(0x011C + (n * 0x20))
  83. /* DSIPHY_SCP */
  84. #define DSI_DSIPHY_CFG0 DSI_REG(0x200 + 0x0000)
  85. #define DSI_DSIPHY_CFG1 DSI_REG(0x200 + 0x0004)
  86. #define DSI_DSIPHY_CFG2 DSI_REG(0x200 + 0x0008)
  87. #define DSI_DSIPHY_CFG5 DSI_REG(0x200 + 0x0014)
  88. #define DSI_DSIPHY_CFG10 DSI_REG(0x200 + 0x0028)
  89. /* DSI_PLL_CTRL_SCP */
  90. #define DSI_PLL_CONTROL DSI_REG(0x300 + 0x0000)
  91. #define DSI_PLL_STATUS DSI_REG(0x300 + 0x0004)
  92. #define DSI_PLL_GO DSI_REG(0x300 + 0x0008)
  93. #define DSI_PLL_CONFIGURATION1 DSI_REG(0x300 + 0x000C)
  94. #define DSI_PLL_CONFIGURATION2 DSI_REG(0x300 + 0x0010)
  95. #define REG_GET(dsidev, idx, start, end) \
  96. FLD_GET(dsi_read_reg(dsidev, idx), start, end)
  97. #define REG_FLD_MOD(dsidev, idx, val, start, end) \
  98. dsi_write_reg(dsidev, idx, FLD_MOD(dsi_read_reg(dsidev, idx), val, start, end))
  99. /* Global interrupts */
  100. #define DSI_IRQ_VC0 (1 << 0)
  101. #define DSI_IRQ_VC1 (1 << 1)
  102. #define DSI_IRQ_VC2 (1 << 2)
  103. #define DSI_IRQ_VC3 (1 << 3)
  104. #define DSI_IRQ_WAKEUP (1 << 4)
  105. #define DSI_IRQ_RESYNC (1 << 5)
  106. #define DSI_IRQ_PLL_LOCK (1 << 7)
  107. #define DSI_IRQ_PLL_UNLOCK (1 << 8)
  108. #define DSI_IRQ_PLL_RECALL (1 << 9)
  109. #define DSI_IRQ_COMPLEXIO_ERR (1 << 10)
  110. #define DSI_IRQ_HS_TX_TIMEOUT (1 << 14)
  111. #define DSI_IRQ_LP_RX_TIMEOUT (1 << 15)
  112. #define DSI_IRQ_TE_TRIGGER (1 << 16)
  113. #define DSI_IRQ_ACK_TRIGGER (1 << 17)
  114. #define DSI_IRQ_SYNC_LOST (1 << 18)
  115. #define DSI_IRQ_LDO_POWER_GOOD (1 << 19)
  116. #define DSI_IRQ_TA_TIMEOUT (1 << 20)
  117. #define DSI_IRQ_ERROR_MASK \
  118. (DSI_IRQ_HS_TX_TIMEOUT | DSI_IRQ_LP_RX_TIMEOUT | DSI_IRQ_SYNC_LOST | \
  119. DSI_IRQ_TA_TIMEOUT)
  120. #define DSI_IRQ_CHANNEL_MASK 0xf
  121. /* Virtual channel interrupts */
  122. #define DSI_VC_IRQ_CS (1 << 0)
  123. #define DSI_VC_IRQ_ECC_CORR (1 << 1)
  124. #define DSI_VC_IRQ_PACKET_SENT (1 << 2)
  125. #define DSI_VC_IRQ_FIFO_TX_OVF (1 << 3)
  126. #define DSI_VC_IRQ_FIFO_RX_OVF (1 << 4)
  127. #define DSI_VC_IRQ_BTA (1 << 5)
  128. #define DSI_VC_IRQ_ECC_NO_CORR (1 << 6)
  129. #define DSI_VC_IRQ_FIFO_TX_UDF (1 << 7)
  130. #define DSI_VC_IRQ_PP_BUSY_CHANGE (1 << 8)
  131. #define DSI_VC_IRQ_ERROR_MASK \
  132. (DSI_VC_IRQ_CS | DSI_VC_IRQ_ECC_CORR | DSI_VC_IRQ_FIFO_TX_OVF | \
  133. DSI_VC_IRQ_FIFO_RX_OVF | DSI_VC_IRQ_ECC_NO_CORR | \
  134. DSI_VC_IRQ_FIFO_TX_UDF)
  135. /* ComplexIO interrupts */
  136. #define DSI_CIO_IRQ_ERRSYNCESC1 (1 << 0)
  137. #define DSI_CIO_IRQ_ERRSYNCESC2 (1 << 1)
  138. #define DSI_CIO_IRQ_ERRSYNCESC3 (1 << 2)
  139. #define DSI_CIO_IRQ_ERRSYNCESC4 (1 << 3)
  140. #define DSI_CIO_IRQ_ERRSYNCESC5 (1 << 4)
  141. #define DSI_CIO_IRQ_ERRESC1 (1 << 5)
  142. #define DSI_CIO_IRQ_ERRESC2 (1 << 6)
  143. #define DSI_CIO_IRQ_ERRESC3 (1 << 7)
  144. #define DSI_CIO_IRQ_ERRESC4 (1 << 8)
  145. #define DSI_CIO_IRQ_ERRESC5 (1 << 9)
  146. #define DSI_CIO_IRQ_ERRCONTROL1 (1 << 10)
  147. #define DSI_CIO_IRQ_ERRCONTROL2 (1 << 11)
  148. #define DSI_CIO_IRQ_ERRCONTROL3 (1 << 12)
  149. #define DSI_CIO_IRQ_ERRCONTROL4 (1 << 13)
  150. #define DSI_CIO_IRQ_ERRCONTROL5 (1 << 14)
  151. #define DSI_CIO_IRQ_STATEULPS1 (1 << 15)
  152. #define DSI_CIO_IRQ_STATEULPS2 (1 << 16)
  153. #define DSI_CIO_IRQ_STATEULPS3 (1 << 17)
  154. #define DSI_CIO_IRQ_STATEULPS4 (1 << 18)
  155. #define DSI_CIO_IRQ_STATEULPS5 (1 << 19)
  156. #define DSI_CIO_IRQ_ERRCONTENTIONLP0_1 (1 << 20)
  157. #define DSI_CIO_IRQ_ERRCONTENTIONLP1_1 (1 << 21)
  158. #define DSI_CIO_IRQ_ERRCONTENTIONLP0_2 (1 << 22)
  159. #define DSI_CIO_IRQ_ERRCONTENTIONLP1_2 (1 << 23)
  160. #define DSI_CIO_IRQ_ERRCONTENTIONLP0_3 (1 << 24)
  161. #define DSI_CIO_IRQ_ERRCONTENTIONLP1_3 (1 << 25)
  162. #define DSI_CIO_IRQ_ERRCONTENTIONLP0_4 (1 << 26)
  163. #define DSI_CIO_IRQ_ERRCONTENTIONLP1_4 (1 << 27)
  164. #define DSI_CIO_IRQ_ERRCONTENTIONLP0_5 (1 << 28)
  165. #define DSI_CIO_IRQ_ERRCONTENTIONLP1_5 (1 << 29)
  166. #define DSI_CIO_IRQ_ULPSACTIVENOT_ALL0 (1 << 30)
  167. #define DSI_CIO_IRQ_ULPSACTIVENOT_ALL1 (1 << 31)
  168. #define DSI_CIO_IRQ_ERROR_MASK \
  169. (DSI_CIO_IRQ_ERRSYNCESC1 | DSI_CIO_IRQ_ERRSYNCESC2 | \
  170. DSI_CIO_IRQ_ERRSYNCESC3 | DSI_CIO_IRQ_ERRSYNCESC4 | \
  171. DSI_CIO_IRQ_ERRSYNCESC5 | \
  172. DSI_CIO_IRQ_ERRESC1 | DSI_CIO_IRQ_ERRESC2 | \
  173. DSI_CIO_IRQ_ERRESC3 | DSI_CIO_IRQ_ERRESC4 | \
  174. DSI_CIO_IRQ_ERRESC5 | \
  175. DSI_CIO_IRQ_ERRCONTROL1 | DSI_CIO_IRQ_ERRCONTROL2 | \
  176. DSI_CIO_IRQ_ERRCONTROL3 | DSI_CIO_IRQ_ERRCONTROL4 | \
  177. DSI_CIO_IRQ_ERRCONTROL5 | \
  178. DSI_CIO_IRQ_ERRCONTENTIONLP0_1 | DSI_CIO_IRQ_ERRCONTENTIONLP1_1 | \
  179. DSI_CIO_IRQ_ERRCONTENTIONLP0_2 | DSI_CIO_IRQ_ERRCONTENTIONLP1_2 | \
  180. DSI_CIO_IRQ_ERRCONTENTIONLP0_3 | DSI_CIO_IRQ_ERRCONTENTIONLP1_3 | \
  181. DSI_CIO_IRQ_ERRCONTENTIONLP0_4 | DSI_CIO_IRQ_ERRCONTENTIONLP1_4 | \
  182. DSI_CIO_IRQ_ERRCONTENTIONLP0_5 | DSI_CIO_IRQ_ERRCONTENTIONLP1_5)
  183. typedef void (*omap_dsi_isr_t) (void *arg, u32 mask);
  184. #define DSI_MAX_NR_ISRS 2
  185. struct dsi_isr_data {
  186. omap_dsi_isr_t isr;
  187. void *arg;
  188. u32 mask;
  189. };
  190. enum fifo_size {
  191. DSI_FIFO_SIZE_0 = 0,
  192. DSI_FIFO_SIZE_32 = 1,
  193. DSI_FIFO_SIZE_64 = 2,
  194. DSI_FIFO_SIZE_96 = 3,
  195. DSI_FIFO_SIZE_128 = 4,
  196. };
  197. enum dsi_vc_source {
  198. DSI_VC_SOURCE_L4 = 0,
  199. DSI_VC_SOURCE_VP,
  200. };
  201. enum dsi_lane {
  202. DSI_CLK_P = 1 << 0,
  203. DSI_CLK_N = 1 << 1,
  204. DSI_DATA1_P = 1 << 2,
  205. DSI_DATA1_N = 1 << 3,
  206. DSI_DATA2_P = 1 << 4,
  207. DSI_DATA2_N = 1 << 5,
  208. DSI_DATA3_P = 1 << 6,
  209. DSI_DATA3_N = 1 << 7,
  210. DSI_DATA4_P = 1 << 8,
  211. DSI_DATA4_N = 1 << 9,
  212. };
  213. struct dsi_update_region {
  214. u16 x, y, w, h;
  215. struct omap_dss_device *device;
  216. };
  217. struct dsi_irq_stats {
  218. unsigned long last_reset;
  219. unsigned irq_count;
  220. unsigned dsi_irqs[32];
  221. unsigned vc_irqs[4][32];
  222. unsigned cio_irqs[32];
  223. };
  224. struct dsi_isr_tables {
  225. struct dsi_isr_data isr_table[DSI_MAX_NR_ISRS];
  226. struct dsi_isr_data isr_table_vc[4][DSI_MAX_NR_ISRS];
  227. struct dsi_isr_data isr_table_cio[DSI_MAX_NR_ISRS];
  228. };
  229. struct dsi_data {
  230. struct platform_device *pdev;
  231. void __iomem *base;
  232. int irq;
  233. struct clk *dss_clk;
  234. struct clk *sys_clk;
  235. int (*enable_pads)(int dsi_id, unsigned lane_mask);
  236. void (*disable_pads)(int dsi_id, unsigned lane_mask);
  237. struct dsi_clock_info current_cinfo;
  238. bool vdds_dsi_enabled;
  239. struct regulator *vdds_dsi_reg;
  240. struct {
  241. enum dsi_vc_source source;
  242. struct omap_dss_device *dssdev;
  243. enum fifo_size fifo_size;
  244. int vc_id;
  245. } vc[4];
  246. struct mutex lock;
  247. struct semaphore bus_lock;
  248. unsigned pll_locked;
  249. spinlock_t irq_lock;
  250. struct dsi_isr_tables isr_tables;
  251. /* space for a copy used by the interrupt handler */
  252. struct dsi_isr_tables isr_tables_copy;
  253. int update_channel;
  254. struct dsi_update_region update_region;
  255. bool te_enabled;
  256. bool ulps_enabled;
  257. void (*framedone_callback)(int, void *);
  258. void *framedone_data;
  259. struct delayed_work framedone_timeout_work;
  260. #ifdef DSI_CATCH_MISSING_TE
  261. struct timer_list te_timer;
  262. #endif
  263. unsigned long cache_req_pck;
  264. unsigned long cache_clk_freq;
  265. struct dsi_clock_info cache_cinfo;
  266. u32 errors;
  267. spinlock_t errors_lock;
  268. #ifdef DEBUG
  269. ktime_t perf_setup_time;
  270. ktime_t perf_start_time;
  271. #endif
  272. int debug_read;
  273. int debug_write;
  274. #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
  275. spinlock_t irq_stats_lock;
  276. struct dsi_irq_stats irq_stats;
  277. #endif
  278. /* DSI PLL Parameter Ranges */
  279. unsigned long regm_max, regn_max;
  280. unsigned long regm_dispc_max, regm_dsi_max;
  281. unsigned long fint_min, fint_max;
  282. unsigned long lpdiv_max;
  283. int num_data_lanes;
  284. unsigned scp_clk_refcount;
  285. };
  286. struct dsi_packet_sent_handler_data {
  287. struct platform_device *dsidev;
  288. struct completion *completion;
  289. };
  290. static struct platform_device *dsi_pdev_map[MAX_NUM_DSI];
  291. #ifdef DEBUG
  292. static unsigned int dsi_perf;
  293. module_param_named(dsi_perf, dsi_perf, bool, 0644);
  294. #endif
  295. static inline struct dsi_data *dsi_get_dsidrv_data(struct platform_device *dsidev)
  296. {
  297. return dev_get_drvdata(&dsidev->dev);
  298. }
  299. static inline struct platform_device *dsi_get_dsidev_from_dssdev(struct omap_dss_device *dssdev)
  300. {
  301. return dsi_pdev_map[dssdev->phy.dsi.module];
  302. }
  303. struct platform_device *dsi_get_dsidev_from_id(int module)
  304. {
  305. return dsi_pdev_map[module];
  306. }
  307. static inline int dsi_get_dsidev_id(struct platform_device *dsidev)
  308. {
  309. return dsidev->id;
  310. }
  311. static inline void dsi_write_reg(struct platform_device *dsidev,
  312. const struct dsi_reg idx, u32 val)
  313. {
  314. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  315. __raw_writel(val, dsi->base + idx.idx);
  316. }
  317. static inline u32 dsi_read_reg(struct platform_device *dsidev,
  318. const struct dsi_reg idx)
  319. {
  320. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  321. return __raw_readl(dsi->base + idx.idx);
  322. }
  323. void dsi_bus_lock(struct omap_dss_device *dssdev)
  324. {
  325. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  326. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  327. down(&dsi->bus_lock);
  328. }
  329. EXPORT_SYMBOL(dsi_bus_lock);
  330. void dsi_bus_unlock(struct omap_dss_device *dssdev)
  331. {
  332. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  333. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  334. up(&dsi->bus_lock);
  335. }
  336. EXPORT_SYMBOL(dsi_bus_unlock);
  337. static bool dsi_bus_is_locked(struct platform_device *dsidev)
  338. {
  339. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  340. return dsi->bus_lock.count == 0;
  341. }
  342. static void dsi_completion_handler(void *data, u32 mask)
  343. {
  344. complete((struct completion *)data);
  345. }
  346. static inline int wait_for_bit_change(struct platform_device *dsidev,
  347. const struct dsi_reg idx, int bitnum, int value)
  348. {
  349. int t = 100000;
  350. while (REG_GET(dsidev, idx, bitnum, bitnum) != value) {
  351. if (--t == 0)
  352. return !value;
  353. }
  354. return value;
  355. }
  356. #ifdef DEBUG
  357. static void dsi_perf_mark_setup(struct platform_device *dsidev)
  358. {
  359. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  360. dsi->perf_setup_time = ktime_get();
  361. }
  362. static void dsi_perf_mark_start(struct platform_device *dsidev)
  363. {
  364. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  365. dsi->perf_start_time = ktime_get();
  366. }
  367. static void dsi_perf_show(struct platform_device *dsidev, const char *name)
  368. {
  369. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  370. ktime_t t, setup_time, trans_time;
  371. u32 total_bytes;
  372. u32 setup_us, trans_us, total_us;
  373. if (!dsi_perf)
  374. return;
  375. t = ktime_get();
  376. setup_time = ktime_sub(dsi->perf_start_time, dsi->perf_setup_time);
  377. setup_us = (u32)ktime_to_us(setup_time);
  378. if (setup_us == 0)
  379. setup_us = 1;
  380. trans_time = ktime_sub(t, dsi->perf_start_time);
  381. trans_us = (u32)ktime_to_us(trans_time);
  382. if (trans_us == 0)
  383. trans_us = 1;
  384. total_us = setup_us + trans_us;
  385. total_bytes = dsi->update_region.w *
  386. dsi->update_region.h *
  387. dsi->update_region.device->ctrl.pixel_size / 8;
  388. printk(KERN_INFO "DSI(%s): %u us + %u us = %u us (%uHz), "
  389. "%u bytes, %u kbytes/sec\n",
  390. name,
  391. setup_us,
  392. trans_us,
  393. total_us,
  394. 1000*1000 / total_us,
  395. total_bytes,
  396. total_bytes * 1000 / total_us);
  397. }
  398. #else
  399. static inline void dsi_perf_mark_setup(struct platform_device *dsidev)
  400. {
  401. }
  402. static inline void dsi_perf_mark_start(struct platform_device *dsidev)
  403. {
  404. }
  405. static inline void dsi_perf_show(struct platform_device *dsidev,
  406. const char *name)
  407. {
  408. }
  409. #endif
  410. static void print_irq_status(u32 status)
  411. {
  412. if (status == 0)
  413. return;
  414. #ifndef VERBOSE_IRQ
  415. if ((status & ~DSI_IRQ_CHANNEL_MASK) == 0)
  416. return;
  417. #endif
  418. printk(KERN_DEBUG "DSI IRQ: 0x%x: ", status);
  419. #define PIS(x) \
  420. if (status & DSI_IRQ_##x) \
  421. printk(#x " ");
  422. #ifdef VERBOSE_IRQ
  423. PIS(VC0);
  424. PIS(VC1);
  425. PIS(VC2);
  426. PIS(VC3);
  427. #endif
  428. PIS(WAKEUP);
  429. PIS(RESYNC);
  430. PIS(PLL_LOCK);
  431. PIS(PLL_UNLOCK);
  432. PIS(PLL_RECALL);
  433. PIS(COMPLEXIO_ERR);
  434. PIS(HS_TX_TIMEOUT);
  435. PIS(LP_RX_TIMEOUT);
  436. PIS(TE_TRIGGER);
  437. PIS(ACK_TRIGGER);
  438. PIS(SYNC_LOST);
  439. PIS(LDO_POWER_GOOD);
  440. PIS(TA_TIMEOUT);
  441. #undef PIS
  442. printk("\n");
  443. }
  444. static void print_irq_status_vc(int channel, u32 status)
  445. {
  446. if (status == 0)
  447. return;
  448. #ifndef VERBOSE_IRQ
  449. if ((status & ~DSI_VC_IRQ_PACKET_SENT) == 0)
  450. return;
  451. #endif
  452. printk(KERN_DEBUG "DSI VC(%d) IRQ 0x%x: ", channel, status);
  453. #define PIS(x) \
  454. if (status & DSI_VC_IRQ_##x) \
  455. printk(#x " ");
  456. PIS(CS);
  457. PIS(ECC_CORR);
  458. #ifdef VERBOSE_IRQ
  459. PIS(PACKET_SENT);
  460. #endif
  461. PIS(FIFO_TX_OVF);
  462. PIS(FIFO_RX_OVF);
  463. PIS(BTA);
  464. PIS(ECC_NO_CORR);
  465. PIS(FIFO_TX_UDF);
  466. PIS(PP_BUSY_CHANGE);
  467. #undef PIS
  468. printk("\n");
  469. }
  470. static void print_irq_status_cio(u32 status)
  471. {
  472. if (status == 0)
  473. return;
  474. printk(KERN_DEBUG "DSI CIO IRQ 0x%x: ", status);
  475. #define PIS(x) \
  476. if (status & DSI_CIO_IRQ_##x) \
  477. printk(#x " ");
  478. PIS(ERRSYNCESC1);
  479. PIS(ERRSYNCESC2);
  480. PIS(ERRSYNCESC3);
  481. PIS(ERRESC1);
  482. PIS(ERRESC2);
  483. PIS(ERRESC3);
  484. PIS(ERRCONTROL1);
  485. PIS(ERRCONTROL2);
  486. PIS(ERRCONTROL3);
  487. PIS(STATEULPS1);
  488. PIS(STATEULPS2);
  489. PIS(STATEULPS3);
  490. PIS(ERRCONTENTIONLP0_1);
  491. PIS(ERRCONTENTIONLP1_1);
  492. PIS(ERRCONTENTIONLP0_2);
  493. PIS(ERRCONTENTIONLP1_2);
  494. PIS(ERRCONTENTIONLP0_3);
  495. PIS(ERRCONTENTIONLP1_3);
  496. PIS(ULPSACTIVENOT_ALL0);
  497. PIS(ULPSACTIVENOT_ALL1);
  498. #undef PIS
  499. printk("\n");
  500. }
  501. #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
  502. static void dsi_collect_irq_stats(struct platform_device *dsidev, u32 irqstatus,
  503. u32 *vcstatus, u32 ciostatus)
  504. {
  505. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  506. int i;
  507. spin_lock(&dsi->irq_stats_lock);
  508. dsi->irq_stats.irq_count++;
  509. dss_collect_irq_stats(irqstatus, dsi->irq_stats.dsi_irqs);
  510. for (i = 0; i < 4; ++i)
  511. dss_collect_irq_stats(vcstatus[i], dsi->irq_stats.vc_irqs[i]);
  512. dss_collect_irq_stats(ciostatus, dsi->irq_stats.cio_irqs);
  513. spin_unlock(&dsi->irq_stats_lock);
  514. }
  515. #else
  516. #define dsi_collect_irq_stats(dsidev, irqstatus, vcstatus, ciostatus)
  517. #endif
  518. static int debug_irq;
  519. static void dsi_handle_irq_errors(struct platform_device *dsidev, u32 irqstatus,
  520. u32 *vcstatus, u32 ciostatus)
  521. {
  522. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  523. int i;
  524. if (irqstatus & DSI_IRQ_ERROR_MASK) {
  525. DSSERR("DSI error, irqstatus %x\n", irqstatus);
  526. print_irq_status(irqstatus);
  527. spin_lock(&dsi->errors_lock);
  528. dsi->errors |= irqstatus & DSI_IRQ_ERROR_MASK;
  529. spin_unlock(&dsi->errors_lock);
  530. } else if (debug_irq) {
  531. print_irq_status(irqstatus);
  532. }
  533. for (i = 0; i < 4; ++i) {
  534. if (vcstatus[i] & DSI_VC_IRQ_ERROR_MASK) {
  535. DSSERR("DSI VC(%d) error, vc irqstatus %x\n",
  536. i, vcstatus[i]);
  537. print_irq_status_vc(i, vcstatus[i]);
  538. } else if (debug_irq) {
  539. print_irq_status_vc(i, vcstatus[i]);
  540. }
  541. }
  542. if (ciostatus & DSI_CIO_IRQ_ERROR_MASK) {
  543. DSSERR("DSI CIO error, cio irqstatus %x\n", ciostatus);
  544. print_irq_status_cio(ciostatus);
  545. } else if (debug_irq) {
  546. print_irq_status_cio(ciostatus);
  547. }
  548. }
  549. static void dsi_call_isrs(struct dsi_isr_data *isr_array,
  550. unsigned isr_array_size, u32 irqstatus)
  551. {
  552. struct dsi_isr_data *isr_data;
  553. int i;
  554. for (i = 0; i < isr_array_size; i++) {
  555. isr_data = &isr_array[i];
  556. if (isr_data->isr && isr_data->mask & irqstatus)
  557. isr_data->isr(isr_data->arg, irqstatus);
  558. }
  559. }
  560. static void dsi_handle_isrs(struct dsi_isr_tables *isr_tables,
  561. u32 irqstatus, u32 *vcstatus, u32 ciostatus)
  562. {
  563. int i;
  564. dsi_call_isrs(isr_tables->isr_table,
  565. ARRAY_SIZE(isr_tables->isr_table),
  566. irqstatus);
  567. for (i = 0; i < 4; ++i) {
  568. if (vcstatus[i] == 0)
  569. continue;
  570. dsi_call_isrs(isr_tables->isr_table_vc[i],
  571. ARRAY_SIZE(isr_tables->isr_table_vc[i]),
  572. vcstatus[i]);
  573. }
  574. if (ciostatus != 0)
  575. dsi_call_isrs(isr_tables->isr_table_cio,
  576. ARRAY_SIZE(isr_tables->isr_table_cio),
  577. ciostatus);
  578. }
  579. static irqreturn_t omap_dsi_irq_handler(int irq, void *arg)
  580. {
  581. struct platform_device *dsidev;
  582. struct dsi_data *dsi;
  583. u32 irqstatus, vcstatus[4], ciostatus;
  584. int i;
  585. dsidev = (struct platform_device *) arg;
  586. dsi = dsi_get_dsidrv_data(dsidev);
  587. spin_lock(&dsi->irq_lock);
  588. irqstatus = dsi_read_reg(dsidev, DSI_IRQSTATUS);
  589. /* IRQ is not for us */
  590. if (!irqstatus) {
  591. spin_unlock(&dsi->irq_lock);
  592. return IRQ_NONE;
  593. }
  594. dsi_write_reg(dsidev, DSI_IRQSTATUS, irqstatus & ~DSI_IRQ_CHANNEL_MASK);
  595. /* flush posted write */
  596. dsi_read_reg(dsidev, DSI_IRQSTATUS);
  597. for (i = 0; i < 4; ++i) {
  598. if ((irqstatus & (1 << i)) == 0) {
  599. vcstatus[i] = 0;
  600. continue;
  601. }
  602. vcstatus[i] = dsi_read_reg(dsidev, DSI_VC_IRQSTATUS(i));
  603. dsi_write_reg(dsidev, DSI_VC_IRQSTATUS(i), vcstatus[i]);
  604. /* flush posted write */
  605. dsi_read_reg(dsidev, DSI_VC_IRQSTATUS(i));
  606. }
  607. if (irqstatus & DSI_IRQ_COMPLEXIO_ERR) {
  608. ciostatus = dsi_read_reg(dsidev, DSI_COMPLEXIO_IRQ_STATUS);
  609. dsi_write_reg(dsidev, DSI_COMPLEXIO_IRQ_STATUS, ciostatus);
  610. /* flush posted write */
  611. dsi_read_reg(dsidev, DSI_COMPLEXIO_IRQ_STATUS);
  612. } else {
  613. ciostatus = 0;
  614. }
  615. #ifdef DSI_CATCH_MISSING_TE
  616. if (irqstatus & DSI_IRQ_TE_TRIGGER)
  617. del_timer(&dsi->te_timer);
  618. #endif
  619. /* make a copy and unlock, so that isrs can unregister
  620. * themselves */
  621. memcpy(&dsi->isr_tables_copy, &dsi->isr_tables,
  622. sizeof(dsi->isr_tables));
  623. spin_unlock(&dsi->irq_lock);
  624. dsi_handle_isrs(&dsi->isr_tables_copy, irqstatus, vcstatus, ciostatus);
  625. dsi_handle_irq_errors(dsidev, irqstatus, vcstatus, ciostatus);
  626. dsi_collect_irq_stats(dsidev, irqstatus, vcstatus, ciostatus);
  627. return IRQ_HANDLED;
  628. }
  629. /* dsi->irq_lock has to be locked by the caller */
  630. static void _omap_dsi_configure_irqs(struct platform_device *dsidev,
  631. struct dsi_isr_data *isr_array,
  632. unsigned isr_array_size, u32 default_mask,
  633. const struct dsi_reg enable_reg,
  634. const struct dsi_reg status_reg)
  635. {
  636. struct dsi_isr_data *isr_data;
  637. u32 mask;
  638. u32 old_mask;
  639. int i;
  640. mask = default_mask;
  641. for (i = 0; i < isr_array_size; i++) {
  642. isr_data = &isr_array[i];
  643. if (isr_data->isr == NULL)
  644. continue;
  645. mask |= isr_data->mask;
  646. }
  647. old_mask = dsi_read_reg(dsidev, enable_reg);
  648. /* clear the irqstatus for newly enabled irqs */
  649. dsi_write_reg(dsidev, status_reg, (mask ^ old_mask) & mask);
  650. dsi_write_reg(dsidev, enable_reg, mask);
  651. /* flush posted writes */
  652. dsi_read_reg(dsidev, enable_reg);
  653. dsi_read_reg(dsidev, status_reg);
  654. }
  655. /* dsi->irq_lock has to be locked by the caller */
  656. static void _omap_dsi_set_irqs(struct platform_device *dsidev)
  657. {
  658. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  659. u32 mask = DSI_IRQ_ERROR_MASK;
  660. #ifdef DSI_CATCH_MISSING_TE
  661. mask |= DSI_IRQ_TE_TRIGGER;
  662. #endif
  663. _omap_dsi_configure_irqs(dsidev, dsi->isr_tables.isr_table,
  664. ARRAY_SIZE(dsi->isr_tables.isr_table), mask,
  665. DSI_IRQENABLE, DSI_IRQSTATUS);
  666. }
  667. /* dsi->irq_lock has to be locked by the caller */
  668. static void _omap_dsi_set_irqs_vc(struct platform_device *dsidev, int vc)
  669. {
  670. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  671. _omap_dsi_configure_irqs(dsidev, dsi->isr_tables.isr_table_vc[vc],
  672. ARRAY_SIZE(dsi->isr_tables.isr_table_vc[vc]),
  673. DSI_VC_IRQ_ERROR_MASK,
  674. DSI_VC_IRQENABLE(vc), DSI_VC_IRQSTATUS(vc));
  675. }
  676. /* dsi->irq_lock has to be locked by the caller */
  677. static void _omap_dsi_set_irqs_cio(struct platform_device *dsidev)
  678. {
  679. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  680. _omap_dsi_configure_irqs(dsidev, dsi->isr_tables.isr_table_cio,
  681. ARRAY_SIZE(dsi->isr_tables.isr_table_cio),
  682. DSI_CIO_IRQ_ERROR_MASK,
  683. DSI_COMPLEXIO_IRQ_ENABLE, DSI_COMPLEXIO_IRQ_STATUS);
  684. }
  685. static void _dsi_initialize_irq(struct platform_device *dsidev)
  686. {
  687. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  688. unsigned long flags;
  689. int vc;
  690. spin_lock_irqsave(&dsi->irq_lock, flags);
  691. memset(&dsi->isr_tables, 0, sizeof(dsi->isr_tables));
  692. _omap_dsi_set_irqs(dsidev);
  693. for (vc = 0; vc < 4; ++vc)
  694. _omap_dsi_set_irqs_vc(dsidev, vc);
  695. _omap_dsi_set_irqs_cio(dsidev);
  696. spin_unlock_irqrestore(&dsi->irq_lock, flags);
  697. }
  698. static int _dsi_register_isr(omap_dsi_isr_t isr, void *arg, u32 mask,
  699. struct dsi_isr_data *isr_array, unsigned isr_array_size)
  700. {
  701. struct dsi_isr_data *isr_data;
  702. int free_idx;
  703. int i;
  704. BUG_ON(isr == NULL);
  705. /* check for duplicate entry and find a free slot */
  706. free_idx = -1;
  707. for (i = 0; i < isr_array_size; i++) {
  708. isr_data = &isr_array[i];
  709. if (isr_data->isr == isr && isr_data->arg == arg &&
  710. isr_data->mask == mask) {
  711. return -EINVAL;
  712. }
  713. if (isr_data->isr == NULL && free_idx == -1)
  714. free_idx = i;
  715. }
  716. if (free_idx == -1)
  717. return -EBUSY;
  718. isr_data = &isr_array[free_idx];
  719. isr_data->isr = isr;
  720. isr_data->arg = arg;
  721. isr_data->mask = mask;
  722. return 0;
  723. }
  724. static int _dsi_unregister_isr(omap_dsi_isr_t isr, void *arg, u32 mask,
  725. struct dsi_isr_data *isr_array, unsigned isr_array_size)
  726. {
  727. struct dsi_isr_data *isr_data;
  728. int i;
  729. for (i = 0; i < isr_array_size; i++) {
  730. isr_data = &isr_array[i];
  731. if (isr_data->isr != isr || isr_data->arg != arg ||
  732. isr_data->mask != mask)
  733. continue;
  734. isr_data->isr = NULL;
  735. isr_data->arg = NULL;
  736. isr_data->mask = 0;
  737. return 0;
  738. }
  739. return -EINVAL;
  740. }
  741. static int dsi_register_isr(struct platform_device *dsidev, omap_dsi_isr_t isr,
  742. void *arg, u32 mask)
  743. {
  744. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  745. unsigned long flags;
  746. int r;
  747. spin_lock_irqsave(&dsi->irq_lock, flags);
  748. r = _dsi_register_isr(isr, arg, mask, dsi->isr_tables.isr_table,
  749. ARRAY_SIZE(dsi->isr_tables.isr_table));
  750. if (r == 0)
  751. _omap_dsi_set_irqs(dsidev);
  752. spin_unlock_irqrestore(&dsi->irq_lock, flags);
  753. return r;
  754. }
  755. static int dsi_unregister_isr(struct platform_device *dsidev,
  756. omap_dsi_isr_t isr, void *arg, u32 mask)
  757. {
  758. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  759. unsigned long flags;
  760. int r;
  761. spin_lock_irqsave(&dsi->irq_lock, flags);
  762. r = _dsi_unregister_isr(isr, arg, mask, dsi->isr_tables.isr_table,
  763. ARRAY_SIZE(dsi->isr_tables.isr_table));
  764. if (r == 0)
  765. _omap_dsi_set_irqs(dsidev);
  766. spin_unlock_irqrestore(&dsi->irq_lock, flags);
  767. return r;
  768. }
  769. static int dsi_register_isr_vc(struct platform_device *dsidev, int channel,
  770. omap_dsi_isr_t isr, void *arg, u32 mask)
  771. {
  772. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  773. unsigned long flags;
  774. int r;
  775. spin_lock_irqsave(&dsi->irq_lock, flags);
  776. r = _dsi_register_isr(isr, arg, mask,
  777. dsi->isr_tables.isr_table_vc[channel],
  778. ARRAY_SIZE(dsi->isr_tables.isr_table_vc[channel]));
  779. if (r == 0)
  780. _omap_dsi_set_irqs_vc(dsidev, channel);
  781. spin_unlock_irqrestore(&dsi->irq_lock, flags);
  782. return r;
  783. }
  784. static int dsi_unregister_isr_vc(struct platform_device *dsidev, int channel,
  785. omap_dsi_isr_t isr, void *arg, u32 mask)
  786. {
  787. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  788. unsigned long flags;
  789. int r;
  790. spin_lock_irqsave(&dsi->irq_lock, flags);
  791. r = _dsi_unregister_isr(isr, arg, mask,
  792. dsi->isr_tables.isr_table_vc[channel],
  793. ARRAY_SIZE(dsi->isr_tables.isr_table_vc[channel]));
  794. if (r == 0)
  795. _omap_dsi_set_irqs_vc(dsidev, channel);
  796. spin_unlock_irqrestore(&dsi->irq_lock, flags);
  797. return r;
  798. }
  799. static int dsi_register_isr_cio(struct platform_device *dsidev,
  800. omap_dsi_isr_t isr, void *arg, u32 mask)
  801. {
  802. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  803. unsigned long flags;
  804. int r;
  805. spin_lock_irqsave(&dsi->irq_lock, flags);
  806. r = _dsi_register_isr(isr, arg, mask, dsi->isr_tables.isr_table_cio,
  807. ARRAY_SIZE(dsi->isr_tables.isr_table_cio));
  808. if (r == 0)
  809. _omap_dsi_set_irqs_cio(dsidev);
  810. spin_unlock_irqrestore(&dsi->irq_lock, flags);
  811. return r;
  812. }
  813. static int dsi_unregister_isr_cio(struct platform_device *dsidev,
  814. omap_dsi_isr_t isr, void *arg, u32 mask)
  815. {
  816. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  817. unsigned long flags;
  818. int r;
  819. spin_lock_irqsave(&dsi->irq_lock, flags);
  820. r = _dsi_unregister_isr(isr, arg, mask, dsi->isr_tables.isr_table_cio,
  821. ARRAY_SIZE(dsi->isr_tables.isr_table_cio));
  822. if (r == 0)
  823. _omap_dsi_set_irqs_cio(dsidev);
  824. spin_unlock_irqrestore(&dsi->irq_lock, flags);
  825. return r;
  826. }
  827. static u32 dsi_get_errors(struct platform_device *dsidev)
  828. {
  829. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  830. unsigned long flags;
  831. u32 e;
  832. spin_lock_irqsave(&dsi->errors_lock, flags);
  833. e = dsi->errors;
  834. dsi->errors = 0;
  835. spin_unlock_irqrestore(&dsi->errors_lock, flags);
  836. return e;
  837. }
  838. int dsi_runtime_get(struct platform_device *dsidev)
  839. {
  840. int r;
  841. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  842. DSSDBG("dsi_runtime_get\n");
  843. r = pm_runtime_get_sync(&dsi->pdev->dev);
  844. WARN_ON(r < 0);
  845. return r < 0 ? r : 0;
  846. }
  847. void dsi_runtime_put(struct platform_device *dsidev)
  848. {
  849. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  850. int r;
  851. DSSDBG("dsi_runtime_put\n");
  852. r = pm_runtime_put(&dsi->pdev->dev);
  853. WARN_ON(r < 0);
  854. }
  855. /* source clock for DSI PLL. this could also be PCLKFREE */
  856. static inline void dsi_enable_pll_clock(struct platform_device *dsidev,
  857. bool enable)
  858. {
  859. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  860. if (enable)
  861. clk_enable(dsi->sys_clk);
  862. else
  863. clk_disable(dsi->sys_clk);
  864. if (enable && dsi->pll_locked) {
  865. if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 1, 1) != 1)
  866. DSSERR("cannot lock PLL when enabling clocks\n");
  867. }
  868. }
  869. #ifdef DEBUG
  870. static void _dsi_print_reset_status(struct platform_device *dsidev)
  871. {
  872. u32 l;
  873. int b0, b1, b2;
  874. if (!dss_debug)
  875. return;
  876. /* A dummy read using the SCP interface to any DSIPHY register is
  877. * required after DSIPHY reset to complete the reset of the DSI complex
  878. * I/O. */
  879. l = dsi_read_reg(dsidev, DSI_DSIPHY_CFG5);
  880. printk(KERN_DEBUG "DSI resets: ");
  881. l = dsi_read_reg(dsidev, DSI_PLL_STATUS);
  882. printk("PLL (%d) ", FLD_GET(l, 0, 0));
  883. l = dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG1);
  884. printk("CIO (%d) ", FLD_GET(l, 29, 29));
  885. if (dss_has_feature(FEAT_DSI_REVERSE_TXCLKESC)) {
  886. b0 = 28;
  887. b1 = 27;
  888. b2 = 26;
  889. } else {
  890. b0 = 24;
  891. b1 = 25;
  892. b2 = 26;
  893. }
  894. l = dsi_read_reg(dsidev, DSI_DSIPHY_CFG5);
  895. printk("PHY (%x%x%x, %d, %d, %d)\n",
  896. FLD_GET(l, b0, b0),
  897. FLD_GET(l, b1, b1),
  898. FLD_GET(l, b2, b2),
  899. FLD_GET(l, 29, 29),
  900. FLD_GET(l, 30, 30),
  901. FLD_GET(l, 31, 31));
  902. }
  903. #else
  904. #define _dsi_print_reset_status(x)
  905. #endif
  906. static inline int dsi_if_enable(struct platform_device *dsidev, bool enable)
  907. {
  908. DSSDBG("dsi_if_enable(%d)\n", enable);
  909. enable = enable ? 1 : 0;
  910. REG_FLD_MOD(dsidev, DSI_CTRL, enable, 0, 0); /* IF_EN */
  911. if (wait_for_bit_change(dsidev, DSI_CTRL, 0, enable) != enable) {
  912. DSSERR("Failed to set dsi_if_enable to %d\n", enable);
  913. return -EIO;
  914. }
  915. return 0;
  916. }
  917. unsigned long dsi_get_pll_hsdiv_dispc_rate(struct platform_device *dsidev)
  918. {
  919. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  920. return dsi->current_cinfo.dsi_pll_hsdiv_dispc_clk;
  921. }
  922. static unsigned long dsi_get_pll_hsdiv_dsi_rate(struct platform_device *dsidev)
  923. {
  924. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  925. return dsi->current_cinfo.dsi_pll_hsdiv_dsi_clk;
  926. }
  927. static unsigned long dsi_get_txbyteclkhs(struct platform_device *dsidev)
  928. {
  929. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  930. return dsi->current_cinfo.clkin4ddr / 16;
  931. }
  932. static unsigned long dsi_fclk_rate(struct platform_device *dsidev)
  933. {
  934. unsigned long r;
  935. int dsi_module = dsi_get_dsidev_id(dsidev);
  936. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  937. if (dss_get_dsi_clk_source(dsi_module) == OMAP_DSS_CLK_SRC_FCK) {
  938. /* DSI FCLK source is DSS_CLK_FCK */
  939. r = clk_get_rate(dsi->dss_clk);
  940. } else {
  941. /* DSI FCLK source is dsi_pll_hsdiv_dsi_clk */
  942. r = dsi_get_pll_hsdiv_dsi_rate(dsidev);
  943. }
  944. return r;
  945. }
  946. static int dsi_set_lp_clk_divisor(struct omap_dss_device *dssdev)
  947. {
  948. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  949. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  950. unsigned long dsi_fclk;
  951. unsigned lp_clk_div;
  952. unsigned long lp_clk;
  953. lp_clk_div = dssdev->clocks.dsi.lp_clk_div;
  954. if (lp_clk_div == 0 || lp_clk_div > dsi->lpdiv_max)
  955. return -EINVAL;
  956. dsi_fclk = dsi_fclk_rate(dsidev);
  957. lp_clk = dsi_fclk / 2 / lp_clk_div;
  958. DSSDBG("LP_CLK_DIV %u, LP_CLK %lu\n", lp_clk_div, lp_clk);
  959. dsi->current_cinfo.lp_clk = lp_clk;
  960. dsi->current_cinfo.lp_clk_div = lp_clk_div;
  961. /* LP_CLK_DIVISOR */
  962. REG_FLD_MOD(dsidev, DSI_CLK_CTRL, lp_clk_div, 12, 0);
  963. /* LP_RX_SYNCHRO_ENABLE */
  964. REG_FLD_MOD(dsidev, DSI_CLK_CTRL, dsi_fclk > 30000000 ? 1 : 0, 21, 21);
  965. return 0;
  966. }
  967. static void dsi_enable_scp_clk(struct platform_device *dsidev)
  968. {
  969. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  970. if (dsi->scp_clk_refcount++ == 0)
  971. REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 1, 14, 14); /* CIO_CLK_ICG */
  972. }
  973. static void dsi_disable_scp_clk(struct platform_device *dsidev)
  974. {
  975. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  976. WARN_ON(dsi->scp_clk_refcount == 0);
  977. if (--dsi->scp_clk_refcount == 0)
  978. REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 0, 14, 14); /* CIO_CLK_ICG */
  979. }
  980. enum dsi_pll_power_state {
  981. DSI_PLL_POWER_OFF = 0x0,
  982. DSI_PLL_POWER_ON_HSCLK = 0x1,
  983. DSI_PLL_POWER_ON_ALL = 0x2,
  984. DSI_PLL_POWER_ON_DIV = 0x3,
  985. };
  986. static int dsi_pll_power(struct platform_device *dsidev,
  987. enum dsi_pll_power_state state)
  988. {
  989. int t = 0;
  990. /* DSI-PLL power command 0x3 is not working */
  991. if (dss_has_feature(FEAT_DSI_PLL_PWR_BUG) &&
  992. state == DSI_PLL_POWER_ON_DIV)
  993. state = DSI_PLL_POWER_ON_ALL;
  994. /* PLL_PWR_CMD */
  995. REG_FLD_MOD(dsidev, DSI_CLK_CTRL, state, 31, 30);
  996. /* PLL_PWR_STATUS */
  997. while (FLD_GET(dsi_read_reg(dsidev, DSI_CLK_CTRL), 29, 28) != state) {
  998. if (++t > 1000) {
  999. DSSERR("Failed to set DSI PLL power mode to %d\n",
  1000. state);
  1001. return -ENODEV;
  1002. }
  1003. udelay(1);
  1004. }
  1005. return 0;
  1006. }
  1007. /* calculate clock rates using dividers in cinfo */
  1008. static int dsi_calc_clock_rates(struct omap_dss_device *dssdev,
  1009. struct dsi_clock_info *cinfo)
  1010. {
  1011. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  1012. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1013. if (cinfo->regn == 0 || cinfo->regn > dsi->regn_max)
  1014. return -EINVAL;
  1015. if (cinfo->regm == 0 || cinfo->regm > dsi->regm_max)
  1016. return -EINVAL;
  1017. if (cinfo->regm_dispc > dsi->regm_dispc_max)
  1018. return -EINVAL;
  1019. if (cinfo->regm_dsi > dsi->regm_dsi_max)
  1020. return -EINVAL;
  1021. if (cinfo->use_sys_clk) {
  1022. cinfo->clkin = clk_get_rate(dsi->sys_clk);
  1023. /* XXX it is unclear if highfreq should be used
  1024. * with DSS_SYS_CLK source also */
  1025. cinfo->highfreq = 0;
  1026. } else {
  1027. cinfo->clkin = dispc_mgr_pclk_rate(dssdev->manager->id);
  1028. if (cinfo->clkin < 32000000)
  1029. cinfo->highfreq = 0;
  1030. else
  1031. cinfo->highfreq = 1;
  1032. }
  1033. cinfo->fint = cinfo->clkin / (cinfo->regn * (cinfo->highfreq ? 2 : 1));
  1034. if (cinfo->fint > dsi->fint_max || cinfo->fint < dsi->fint_min)
  1035. return -EINVAL;
  1036. cinfo->clkin4ddr = 2 * cinfo->regm * cinfo->fint;
  1037. if (cinfo->clkin4ddr > 1800 * 1000 * 1000)
  1038. return -EINVAL;
  1039. if (cinfo->regm_dispc > 0)
  1040. cinfo->dsi_pll_hsdiv_dispc_clk =
  1041. cinfo->clkin4ddr / cinfo->regm_dispc;
  1042. else
  1043. cinfo->dsi_pll_hsdiv_dispc_clk = 0;
  1044. if (cinfo->regm_dsi > 0)
  1045. cinfo->dsi_pll_hsdiv_dsi_clk =
  1046. cinfo->clkin4ddr / cinfo->regm_dsi;
  1047. else
  1048. cinfo->dsi_pll_hsdiv_dsi_clk = 0;
  1049. return 0;
  1050. }
  1051. int dsi_pll_calc_clock_div_pck(struct platform_device *dsidev, bool is_tft,
  1052. unsigned long req_pck, struct dsi_clock_info *dsi_cinfo,
  1053. struct dispc_clock_info *dispc_cinfo)
  1054. {
  1055. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1056. struct dsi_clock_info cur, best;
  1057. struct dispc_clock_info best_dispc;
  1058. int min_fck_per_pck;
  1059. int match = 0;
  1060. unsigned long dss_sys_clk, max_dss_fck;
  1061. dss_sys_clk = clk_get_rate(dsi->sys_clk);
  1062. max_dss_fck = dss_feat_get_param_max(FEAT_PARAM_DSS_FCK);
  1063. if (req_pck == dsi->cache_req_pck &&
  1064. dsi->cache_cinfo.clkin == dss_sys_clk) {
  1065. DSSDBG("DSI clock info found from cache\n");
  1066. *dsi_cinfo = dsi->cache_cinfo;
  1067. dispc_find_clk_divs(is_tft, req_pck,
  1068. dsi_cinfo->dsi_pll_hsdiv_dispc_clk, dispc_cinfo);
  1069. return 0;
  1070. }
  1071. min_fck_per_pck = CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK;
  1072. if (min_fck_per_pck &&
  1073. req_pck * min_fck_per_pck > max_dss_fck) {
  1074. DSSERR("Requested pixel clock not possible with the current "
  1075. "OMAP2_DSS_MIN_FCK_PER_PCK setting. Turning "
  1076. "the constraint off.\n");
  1077. min_fck_per_pck = 0;
  1078. }
  1079. DSSDBG("dsi_pll_calc\n");
  1080. retry:
  1081. memset(&best, 0, sizeof(best));
  1082. memset(&best_dispc, 0, sizeof(best_dispc));
  1083. memset(&cur, 0, sizeof(cur));
  1084. cur.clkin = dss_sys_clk;
  1085. cur.use_sys_clk = 1;
  1086. cur.highfreq = 0;
  1087. /* no highfreq: 0.75MHz < Fint = clkin / regn < 2.1MHz */
  1088. /* highfreq: 0.75MHz < Fint = clkin / (2*regn) < 2.1MHz */
  1089. /* To reduce PLL lock time, keep Fint high (around 2 MHz) */
  1090. for (cur.regn = 1; cur.regn < dsi->regn_max; ++cur.regn) {
  1091. if (cur.highfreq == 0)
  1092. cur.fint = cur.clkin / cur.regn;
  1093. else
  1094. cur.fint = cur.clkin / (2 * cur.regn);
  1095. if (cur.fint > dsi->fint_max || cur.fint < dsi->fint_min)
  1096. continue;
  1097. /* DSIPHY(MHz) = (2 * regm / regn) * (clkin / (highfreq + 1)) */
  1098. for (cur.regm = 1; cur.regm < dsi->regm_max; ++cur.regm) {
  1099. unsigned long a, b;
  1100. a = 2 * cur.regm * (cur.clkin/1000);
  1101. b = cur.regn * (cur.highfreq + 1);
  1102. cur.clkin4ddr = a / b * 1000;
  1103. if (cur.clkin4ddr > 1800 * 1000 * 1000)
  1104. break;
  1105. /* dsi_pll_hsdiv_dispc_clk(MHz) =
  1106. * DSIPHY(MHz) / regm_dispc < 173MHz/186Mhz */
  1107. for (cur.regm_dispc = 1; cur.regm_dispc <
  1108. dsi->regm_dispc_max; ++cur.regm_dispc) {
  1109. struct dispc_clock_info cur_dispc;
  1110. cur.dsi_pll_hsdiv_dispc_clk =
  1111. cur.clkin4ddr / cur.regm_dispc;
  1112. /* this will narrow down the search a bit,
  1113. * but still give pixclocks below what was
  1114. * requested */
  1115. if (cur.dsi_pll_hsdiv_dispc_clk < req_pck)
  1116. break;
  1117. if (cur.dsi_pll_hsdiv_dispc_clk > max_dss_fck)
  1118. continue;
  1119. if (min_fck_per_pck &&
  1120. cur.dsi_pll_hsdiv_dispc_clk <
  1121. req_pck * min_fck_per_pck)
  1122. continue;
  1123. match = 1;
  1124. dispc_find_clk_divs(is_tft, req_pck,
  1125. cur.dsi_pll_hsdiv_dispc_clk,
  1126. &cur_dispc);
  1127. if (abs(cur_dispc.pck - req_pck) <
  1128. abs(best_dispc.pck - req_pck)) {
  1129. best = cur;
  1130. best_dispc = cur_dispc;
  1131. if (cur_dispc.pck == req_pck)
  1132. goto found;
  1133. }
  1134. }
  1135. }
  1136. }
  1137. found:
  1138. if (!match) {
  1139. if (min_fck_per_pck) {
  1140. DSSERR("Could not find suitable clock settings.\n"
  1141. "Turning FCK/PCK constraint off and"
  1142. "trying again.\n");
  1143. min_fck_per_pck = 0;
  1144. goto retry;
  1145. }
  1146. DSSERR("Could not find suitable clock settings.\n");
  1147. return -EINVAL;
  1148. }
  1149. /* dsi_pll_hsdiv_dsi_clk (regm_dsi) is not used */
  1150. best.regm_dsi = 0;
  1151. best.dsi_pll_hsdiv_dsi_clk = 0;
  1152. if (dsi_cinfo)
  1153. *dsi_cinfo = best;
  1154. if (dispc_cinfo)
  1155. *dispc_cinfo = best_dispc;
  1156. dsi->cache_req_pck = req_pck;
  1157. dsi->cache_clk_freq = 0;
  1158. dsi->cache_cinfo = best;
  1159. return 0;
  1160. }
  1161. int dsi_pll_set_clock_div(struct platform_device *dsidev,
  1162. struct dsi_clock_info *cinfo)
  1163. {
  1164. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1165. int r = 0;
  1166. u32 l;
  1167. int f = 0;
  1168. u8 regn_start, regn_end, regm_start, regm_end;
  1169. u8 regm_dispc_start, regm_dispc_end, regm_dsi_start, regm_dsi_end;
  1170. DSSDBGF();
  1171. dsi->current_cinfo.use_sys_clk = cinfo->use_sys_clk;
  1172. dsi->current_cinfo.highfreq = cinfo->highfreq;
  1173. dsi->current_cinfo.fint = cinfo->fint;
  1174. dsi->current_cinfo.clkin4ddr = cinfo->clkin4ddr;
  1175. dsi->current_cinfo.dsi_pll_hsdiv_dispc_clk =
  1176. cinfo->dsi_pll_hsdiv_dispc_clk;
  1177. dsi->current_cinfo.dsi_pll_hsdiv_dsi_clk =
  1178. cinfo->dsi_pll_hsdiv_dsi_clk;
  1179. dsi->current_cinfo.regn = cinfo->regn;
  1180. dsi->current_cinfo.regm = cinfo->regm;
  1181. dsi->current_cinfo.regm_dispc = cinfo->regm_dispc;
  1182. dsi->current_cinfo.regm_dsi = cinfo->regm_dsi;
  1183. DSSDBG("DSI Fint %ld\n", cinfo->fint);
  1184. DSSDBG("clkin (%s) rate %ld, highfreq %d\n",
  1185. cinfo->use_sys_clk ? "dss_sys_clk" : "pclkfree",
  1186. cinfo->clkin,
  1187. cinfo->highfreq);
  1188. /* DSIPHY == CLKIN4DDR */
  1189. DSSDBG("CLKIN4DDR = 2 * %d / %d * %lu / %d = %lu\n",
  1190. cinfo->regm,
  1191. cinfo->regn,
  1192. cinfo->clkin,
  1193. cinfo->highfreq + 1,
  1194. cinfo->clkin4ddr);
  1195. DSSDBG("Data rate on 1 DSI lane %ld Mbps\n",
  1196. cinfo->clkin4ddr / 1000 / 1000 / 2);
  1197. DSSDBG("Clock lane freq %ld Hz\n", cinfo->clkin4ddr / 4);
  1198. DSSDBG("regm_dispc = %d, %s (%s) = %lu\n", cinfo->regm_dispc,
  1199. dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC),
  1200. dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC),
  1201. cinfo->dsi_pll_hsdiv_dispc_clk);
  1202. DSSDBG("regm_dsi = %d, %s (%s) = %lu\n", cinfo->regm_dsi,
  1203. dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI),
  1204. dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI),
  1205. cinfo->dsi_pll_hsdiv_dsi_clk);
  1206. dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGN, &regn_start, &regn_end);
  1207. dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGM, &regm_start, &regm_end);
  1208. dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGM_DISPC, &regm_dispc_start,
  1209. &regm_dispc_end);
  1210. dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGM_DSI, &regm_dsi_start,
  1211. &regm_dsi_end);
  1212. /* DSI_PLL_AUTOMODE = manual */
  1213. REG_FLD_MOD(dsidev, DSI_PLL_CONTROL, 0, 0, 0);
  1214. l = dsi_read_reg(dsidev, DSI_PLL_CONFIGURATION1);
  1215. l = FLD_MOD(l, 1, 0, 0); /* DSI_PLL_STOPMODE */
  1216. /* DSI_PLL_REGN */
  1217. l = FLD_MOD(l, cinfo->regn - 1, regn_start, regn_end);
  1218. /* DSI_PLL_REGM */
  1219. l = FLD_MOD(l, cinfo->regm, regm_start, regm_end);
  1220. /* DSI_CLOCK_DIV */
  1221. l = FLD_MOD(l, cinfo->regm_dispc > 0 ? cinfo->regm_dispc - 1 : 0,
  1222. regm_dispc_start, regm_dispc_end);
  1223. /* DSIPROTO_CLOCK_DIV */
  1224. l = FLD_MOD(l, cinfo->regm_dsi > 0 ? cinfo->regm_dsi - 1 : 0,
  1225. regm_dsi_start, regm_dsi_end);
  1226. dsi_write_reg(dsidev, DSI_PLL_CONFIGURATION1, l);
  1227. BUG_ON(cinfo->fint < dsi->fint_min || cinfo->fint > dsi->fint_max);
  1228. if (dss_has_feature(FEAT_DSI_PLL_FREQSEL)) {
  1229. f = cinfo->fint < 1000000 ? 0x3 :
  1230. cinfo->fint < 1250000 ? 0x4 :
  1231. cinfo->fint < 1500000 ? 0x5 :
  1232. cinfo->fint < 1750000 ? 0x6 :
  1233. 0x7;
  1234. }
  1235. l = dsi_read_reg(dsidev, DSI_PLL_CONFIGURATION2);
  1236. if (dss_has_feature(FEAT_DSI_PLL_FREQSEL))
  1237. l = FLD_MOD(l, f, 4, 1); /* DSI_PLL_FREQSEL */
  1238. l = FLD_MOD(l, cinfo->use_sys_clk ? 0 : 1,
  1239. 11, 11); /* DSI_PLL_CLKSEL */
  1240. l = FLD_MOD(l, cinfo->highfreq,
  1241. 12, 12); /* DSI_PLL_HIGHFREQ */
  1242. l = FLD_MOD(l, 1, 13, 13); /* DSI_PLL_REFEN */
  1243. l = FLD_MOD(l, 0, 14, 14); /* DSIPHY_CLKINEN */
  1244. l = FLD_MOD(l, 1, 20, 20); /* DSI_HSDIVBYPASS */
  1245. dsi_write_reg(dsidev, DSI_PLL_CONFIGURATION2, l);
  1246. REG_FLD_MOD(dsidev, DSI_PLL_GO, 1, 0, 0); /* DSI_PLL_GO */
  1247. if (wait_for_bit_change(dsidev, DSI_PLL_GO, 0, 0) != 0) {
  1248. DSSERR("dsi pll go bit not going down.\n");
  1249. r = -EIO;
  1250. goto err;
  1251. }
  1252. if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 1, 1) != 1) {
  1253. DSSERR("cannot lock PLL\n");
  1254. r = -EIO;
  1255. goto err;
  1256. }
  1257. dsi->pll_locked = 1;
  1258. l = dsi_read_reg(dsidev, DSI_PLL_CONFIGURATION2);
  1259. l = FLD_MOD(l, 0, 0, 0); /* DSI_PLL_IDLE */
  1260. l = FLD_MOD(l, 0, 5, 5); /* DSI_PLL_PLLLPMODE */
  1261. l = FLD_MOD(l, 0, 6, 6); /* DSI_PLL_LOWCURRSTBY */
  1262. l = FLD_MOD(l, 0, 7, 7); /* DSI_PLL_TIGHTPHASELOCK */
  1263. l = FLD_MOD(l, 0, 8, 8); /* DSI_PLL_DRIFTGUARDEN */
  1264. l = FLD_MOD(l, 0, 10, 9); /* DSI_PLL_LOCKSEL */
  1265. l = FLD_MOD(l, 1, 13, 13); /* DSI_PLL_REFEN */
  1266. l = FLD_MOD(l, 1, 14, 14); /* DSIPHY_CLKINEN */
  1267. l = FLD_MOD(l, 0, 15, 15); /* DSI_BYPASSEN */
  1268. l = FLD_MOD(l, 1, 16, 16); /* DSS_CLOCK_EN */
  1269. l = FLD_MOD(l, 0, 17, 17); /* DSS_CLOCK_PWDN */
  1270. l = FLD_MOD(l, 1, 18, 18); /* DSI_PROTO_CLOCK_EN */
  1271. l = FLD_MOD(l, 0, 19, 19); /* DSI_PROTO_CLOCK_PWDN */
  1272. l = FLD_MOD(l, 0, 20, 20); /* DSI_HSDIVBYPASS */
  1273. dsi_write_reg(dsidev, DSI_PLL_CONFIGURATION2, l);
  1274. DSSDBG("PLL config done\n");
  1275. err:
  1276. return r;
  1277. }
  1278. int dsi_pll_init(struct platform_device *dsidev, bool enable_hsclk,
  1279. bool enable_hsdiv)
  1280. {
  1281. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1282. int r = 0;
  1283. enum dsi_pll_power_state pwstate;
  1284. DSSDBG("PLL init\n");
  1285. if (dsi->vdds_dsi_reg == NULL) {
  1286. struct regulator *vdds_dsi;
  1287. vdds_dsi = regulator_get(&dsi->pdev->dev, "vdds_dsi");
  1288. if (IS_ERR(vdds_dsi)) {
  1289. DSSERR("can't get VDDS_DSI regulator\n");
  1290. return PTR_ERR(vdds_dsi);
  1291. }
  1292. dsi->vdds_dsi_reg = vdds_dsi;
  1293. }
  1294. dsi_enable_pll_clock(dsidev, 1);
  1295. /*
  1296. * Note: SCP CLK is not required on OMAP3, but it is required on OMAP4.
  1297. */
  1298. dsi_enable_scp_clk(dsidev);
  1299. if (!dsi->vdds_dsi_enabled) {
  1300. r = regulator_enable(dsi->vdds_dsi_reg);
  1301. if (r)
  1302. goto err0;
  1303. dsi->vdds_dsi_enabled = true;
  1304. }
  1305. /* XXX PLL does not come out of reset without this... */
  1306. dispc_pck_free_enable(1);
  1307. if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 0, 1) != 1) {
  1308. DSSERR("PLL not coming out of reset.\n");
  1309. r = -ENODEV;
  1310. dispc_pck_free_enable(0);
  1311. goto err1;
  1312. }
  1313. /* XXX ... but if left on, we get problems when planes do not
  1314. * fill the whole display. No idea about this */
  1315. dispc_pck_free_enable(0);
  1316. if (enable_hsclk && enable_hsdiv)
  1317. pwstate = DSI_PLL_POWER_ON_ALL;
  1318. else if (enable_hsclk)
  1319. pwstate = DSI_PLL_POWER_ON_HSCLK;
  1320. else if (enable_hsdiv)
  1321. pwstate = DSI_PLL_POWER_ON_DIV;
  1322. else
  1323. pwstate = DSI_PLL_POWER_OFF;
  1324. r = dsi_pll_power(dsidev, pwstate);
  1325. if (r)
  1326. goto err1;
  1327. DSSDBG("PLL init done\n");
  1328. return 0;
  1329. err1:
  1330. if (dsi->vdds_dsi_enabled) {
  1331. regulator_disable(dsi->vdds_dsi_reg);
  1332. dsi->vdds_dsi_enabled = false;
  1333. }
  1334. err0:
  1335. dsi_disable_scp_clk(dsidev);
  1336. dsi_enable_pll_clock(dsidev, 0);
  1337. return r;
  1338. }
  1339. void dsi_pll_uninit(struct platform_device *dsidev, bool disconnect_lanes)
  1340. {
  1341. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1342. dsi->pll_locked = 0;
  1343. dsi_pll_power(dsidev, DSI_PLL_POWER_OFF);
  1344. if (disconnect_lanes) {
  1345. WARN_ON(!dsi->vdds_dsi_enabled);
  1346. regulator_disable(dsi->vdds_dsi_reg);
  1347. dsi->vdds_dsi_enabled = false;
  1348. }
  1349. dsi_disable_scp_clk(dsidev);
  1350. dsi_enable_pll_clock(dsidev, 0);
  1351. DSSDBG("PLL uninit done\n");
  1352. }
  1353. static void dsi_dump_dsidev_clocks(struct platform_device *dsidev,
  1354. struct seq_file *s)
  1355. {
  1356. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1357. struct dsi_clock_info *cinfo = &dsi->current_cinfo;
  1358. enum omap_dss_clk_source dispc_clk_src, dsi_clk_src;
  1359. int dsi_module = dsi_get_dsidev_id(dsidev);
  1360. dispc_clk_src = dss_get_dispc_clk_source();
  1361. dsi_clk_src = dss_get_dsi_clk_source(dsi_module);
  1362. if (dsi_runtime_get(dsidev))
  1363. return;
  1364. seq_printf(s, "- DSI%d PLL -\n", dsi_module + 1);
  1365. seq_printf(s, "dsi pll source = %s\n",
  1366. cinfo->use_sys_clk ? "dss_sys_clk" : "pclkfree");
  1367. seq_printf(s, "Fint\t\t%-16luregn %u\n", cinfo->fint, cinfo->regn);
  1368. seq_printf(s, "CLKIN4DDR\t%-16luregm %u\n",
  1369. cinfo->clkin4ddr, cinfo->regm);
  1370. seq_printf(s, "%s (%s)\t%-16luregm_dispc %u\t(%s)\n",
  1371. dss_get_generic_clk_source_name(dispc_clk_src),
  1372. dss_feat_get_clk_source_name(dispc_clk_src),
  1373. cinfo->dsi_pll_hsdiv_dispc_clk,
  1374. cinfo->regm_dispc,
  1375. dispc_clk_src == OMAP_DSS_CLK_SRC_FCK ?
  1376. "off" : "on");
  1377. seq_printf(s, "%s (%s)\t%-16luregm_dsi %u\t(%s)\n",
  1378. dss_get_generic_clk_source_name(dsi_clk_src),
  1379. dss_feat_get_clk_source_name(dsi_clk_src),
  1380. cinfo->dsi_pll_hsdiv_dsi_clk,
  1381. cinfo->regm_dsi,
  1382. dsi_clk_src == OMAP_DSS_CLK_SRC_FCK ?
  1383. "off" : "on");
  1384. seq_printf(s, "- DSI%d -\n", dsi_module + 1);
  1385. seq_printf(s, "dsi fclk source = %s (%s)\n",
  1386. dss_get_generic_clk_source_name(dsi_clk_src),
  1387. dss_feat_get_clk_source_name(dsi_clk_src));
  1388. seq_printf(s, "DSI_FCLK\t%lu\n", dsi_fclk_rate(dsidev));
  1389. seq_printf(s, "DDR_CLK\t\t%lu\n",
  1390. cinfo->clkin4ddr / 4);
  1391. seq_printf(s, "TxByteClkHS\t%lu\n", dsi_get_txbyteclkhs(dsidev));
  1392. seq_printf(s, "LP_CLK\t\t%lu\n", cinfo->lp_clk);
  1393. dsi_runtime_put(dsidev);
  1394. }
  1395. void dsi_dump_clocks(struct seq_file *s)
  1396. {
  1397. struct platform_device *dsidev;
  1398. int i;
  1399. for (i = 0; i < MAX_NUM_DSI; i++) {
  1400. dsidev = dsi_get_dsidev_from_id(i);
  1401. if (dsidev)
  1402. dsi_dump_dsidev_clocks(dsidev, s);
  1403. }
  1404. }
  1405. #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
  1406. static void dsi_dump_dsidev_irqs(struct platform_device *dsidev,
  1407. struct seq_file *s)
  1408. {
  1409. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1410. unsigned long flags;
  1411. struct dsi_irq_stats stats;
  1412. int dsi_module = dsi_get_dsidev_id(dsidev);
  1413. spin_lock_irqsave(&dsi->irq_stats_lock, flags);
  1414. stats = dsi->irq_stats;
  1415. memset(&dsi->irq_stats, 0, sizeof(dsi->irq_stats));
  1416. dsi->irq_stats.last_reset = jiffies;
  1417. spin_unlock_irqrestore(&dsi->irq_stats_lock, flags);
  1418. seq_printf(s, "period %u ms\n",
  1419. jiffies_to_msecs(jiffies - stats.last_reset));
  1420. seq_printf(s, "irqs %d\n", stats.irq_count);
  1421. #define PIS(x) \
  1422. seq_printf(s, "%-20s %10d\n", #x, stats.dsi_irqs[ffs(DSI_IRQ_##x)-1]);
  1423. seq_printf(s, "-- DSI%d interrupts --\n", dsi_module + 1);
  1424. PIS(VC0);
  1425. PIS(VC1);
  1426. PIS(VC2);
  1427. PIS(VC3);
  1428. PIS(WAKEUP);
  1429. PIS(RESYNC);
  1430. PIS(PLL_LOCK);
  1431. PIS(PLL_UNLOCK);
  1432. PIS(PLL_RECALL);
  1433. PIS(COMPLEXIO_ERR);
  1434. PIS(HS_TX_TIMEOUT);
  1435. PIS(LP_RX_TIMEOUT);
  1436. PIS(TE_TRIGGER);
  1437. PIS(ACK_TRIGGER);
  1438. PIS(SYNC_LOST);
  1439. PIS(LDO_POWER_GOOD);
  1440. PIS(TA_TIMEOUT);
  1441. #undef PIS
  1442. #define PIS(x) \
  1443. seq_printf(s, "%-20s %10d %10d %10d %10d\n", #x, \
  1444. stats.vc_irqs[0][ffs(DSI_VC_IRQ_##x)-1], \
  1445. stats.vc_irqs[1][ffs(DSI_VC_IRQ_##x)-1], \
  1446. stats.vc_irqs[2][ffs(DSI_VC_IRQ_##x)-1], \
  1447. stats.vc_irqs[3][ffs(DSI_VC_IRQ_##x)-1]);
  1448. seq_printf(s, "-- VC interrupts --\n");
  1449. PIS(CS);
  1450. PIS(ECC_CORR);
  1451. PIS(PACKET_SENT);
  1452. PIS(FIFO_TX_OVF);
  1453. PIS(FIFO_RX_OVF);
  1454. PIS(BTA);
  1455. PIS(ECC_NO_CORR);
  1456. PIS(FIFO_TX_UDF);
  1457. PIS(PP_BUSY_CHANGE);
  1458. #undef PIS
  1459. #define PIS(x) \
  1460. seq_printf(s, "%-20s %10d\n", #x, \
  1461. stats.cio_irqs[ffs(DSI_CIO_IRQ_##x)-1]);
  1462. seq_printf(s, "-- CIO interrupts --\n");
  1463. PIS(ERRSYNCESC1);
  1464. PIS(ERRSYNCESC2);
  1465. PIS(ERRSYNCESC3);
  1466. PIS(ERRESC1);
  1467. PIS(ERRESC2);
  1468. PIS(ERRESC3);
  1469. PIS(ERRCONTROL1);
  1470. PIS(ERRCONTROL2);
  1471. PIS(ERRCONTROL3);
  1472. PIS(STATEULPS1);
  1473. PIS(STATEULPS2);
  1474. PIS(STATEULPS3);
  1475. PIS(ERRCONTENTIONLP0_1);
  1476. PIS(ERRCONTENTIONLP1_1);
  1477. PIS(ERRCONTENTIONLP0_2);
  1478. PIS(ERRCONTENTIONLP1_2);
  1479. PIS(ERRCONTENTIONLP0_3);
  1480. PIS(ERRCONTENTIONLP1_3);
  1481. PIS(ULPSACTIVENOT_ALL0);
  1482. PIS(ULPSACTIVENOT_ALL1);
  1483. #undef PIS
  1484. }
  1485. static void dsi1_dump_irqs(struct seq_file *s)
  1486. {
  1487. struct platform_device *dsidev = dsi_get_dsidev_from_id(0);
  1488. dsi_dump_dsidev_irqs(dsidev, s);
  1489. }
  1490. static void dsi2_dump_irqs(struct seq_file *s)
  1491. {
  1492. struct platform_device *dsidev = dsi_get_dsidev_from_id(1);
  1493. dsi_dump_dsidev_irqs(dsidev, s);
  1494. }
  1495. void dsi_create_debugfs_files_irq(struct dentry *debugfs_dir,
  1496. const struct file_operations *debug_fops)
  1497. {
  1498. struct platform_device *dsidev;
  1499. dsidev = dsi_get_dsidev_from_id(0);
  1500. if (dsidev)
  1501. debugfs_create_file("dsi1_irqs", S_IRUGO, debugfs_dir,
  1502. &dsi1_dump_irqs, debug_fops);
  1503. dsidev = dsi_get_dsidev_from_id(1);
  1504. if (dsidev)
  1505. debugfs_create_file("dsi2_irqs", S_IRUGO, debugfs_dir,
  1506. &dsi2_dump_irqs, debug_fops);
  1507. }
  1508. #endif
  1509. static void dsi_dump_dsidev_regs(struct platform_device *dsidev,
  1510. struct seq_file *s)
  1511. {
  1512. #define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, dsi_read_reg(dsidev, r))
  1513. if (dsi_runtime_get(dsidev))
  1514. return;
  1515. dsi_enable_scp_clk(dsidev);
  1516. DUMPREG(DSI_REVISION);
  1517. DUMPREG(DSI_SYSCONFIG);
  1518. DUMPREG(DSI_SYSSTATUS);
  1519. DUMPREG(DSI_IRQSTATUS);
  1520. DUMPREG(DSI_IRQENABLE);
  1521. DUMPREG(DSI_CTRL);
  1522. DUMPREG(DSI_COMPLEXIO_CFG1);
  1523. DUMPREG(DSI_COMPLEXIO_IRQ_STATUS);
  1524. DUMPREG(DSI_COMPLEXIO_IRQ_ENABLE);
  1525. DUMPREG(DSI_CLK_CTRL);
  1526. DUMPREG(DSI_TIMING1);
  1527. DUMPREG(DSI_TIMING2);
  1528. DUMPREG(DSI_VM_TIMING1);
  1529. DUMPREG(DSI_VM_TIMING2);
  1530. DUMPREG(DSI_VM_TIMING3);
  1531. DUMPREG(DSI_CLK_TIMING);
  1532. DUMPREG(DSI_TX_FIFO_VC_SIZE);
  1533. DUMPREG(DSI_RX_FIFO_VC_SIZE);
  1534. DUMPREG(DSI_COMPLEXIO_CFG2);
  1535. DUMPREG(DSI_RX_FIFO_VC_FULLNESS);
  1536. DUMPREG(DSI_VM_TIMING4);
  1537. DUMPREG(DSI_TX_FIFO_VC_EMPTINESS);
  1538. DUMPREG(DSI_VM_TIMING5);
  1539. DUMPREG(DSI_VM_TIMING6);
  1540. DUMPREG(DSI_VM_TIMING7);
  1541. DUMPREG(DSI_STOPCLK_TIMING);
  1542. DUMPREG(DSI_VC_CTRL(0));
  1543. DUMPREG(DSI_VC_TE(0));
  1544. DUMPREG(DSI_VC_LONG_PACKET_HEADER(0));
  1545. DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(0));
  1546. DUMPREG(DSI_VC_SHORT_PACKET_HEADER(0));
  1547. DUMPREG(DSI_VC_IRQSTATUS(0));
  1548. DUMPREG(DSI_VC_IRQENABLE(0));
  1549. DUMPREG(DSI_VC_CTRL(1));
  1550. DUMPREG(DSI_VC_TE(1));
  1551. DUMPREG(DSI_VC_LONG_PACKET_HEADER(1));
  1552. DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(1));
  1553. DUMPREG(DSI_VC_SHORT_PACKET_HEADER(1));
  1554. DUMPREG(DSI_VC_IRQSTATUS(1));
  1555. DUMPREG(DSI_VC_IRQENABLE(1));
  1556. DUMPREG(DSI_VC_CTRL(2));
  1557. DUMPREG(DSI_VC_TE(2));
  1558. DUMPREG(DSI_VC_LONG_PACKET_HEADER(2));
  1559. DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(2));
  1560. DUMPREG(DSI_VC_SHORT_PACKET_HEADER(2));
  1561. DUMPREG(DSI_VC_IRQSTATUS(2));
  1562. DUMPREG(DSI_VC_IRQENABLE(2));
  1563. DUMPREG(DSI_VC_CTRL(3));
  1564. DUMPREG(DSI_VC_TE(3));
  1565. DUMPREG(DSI_VC_LONG_PACKET_HEADER(3));
  1566. DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(3));
  1567. DUMPREG(DSI_VC_SHORT_PACKET_HEADER(3));
  1568. DUMPREG(DSI_VC_IRQSTATUS(3));
  1569. DUMPREG(DSI_VC_IRQENABLE(3));
  1570. DUMPREG(DSI_DSIPHY_CFG0);
  1571. DUMPREG(DSI_DSIPHY_CFG1);
  1572. DUMPREG(DSI_DSIPHY_CFG2);
  1573. DUMPREG(DSI_DSIPHY_CFG5);
  1574. DUMPREG(DSI_PLL_CONTROL);
  1575. DUMPREG(DSI_PLL_STATUS);
  1576. DUMPREG(DSI_PLL_GO);
  1577. DUMPREG(DSI_PLL_CONFIGURATION1);
  1578. DUMPREG(DSI_PLL_CONFIGURATION2);
  1579. dsi_disable_scp_clk(dsidev);
  1580. dsi_runtime_put(dsidev);
  1581. #undef DUMPREG
  1582. }
  1583. static void dsi1_dump_regs(struct seq_file *s)
  1584. {
  1585. struct platform_device *dsidev = dsi_get_dsidev_from_id(0);
  1586. dsi_dump_dsidev_regs(dsidev, s);
  1587. }
  1588. static void dsi2_dump_regs(struct seq_file *s)
  1589. {
  1590. struct platform_device *dsidev = dsi_get_dsidev_from_id(1);
  1591. dsi_dump_dsidev_regs(dsidev, s);
  1592. }
  1593. void dsi_create_debugfs_files_reg(struct dentry *debugfs_dir,
  1594. const struct file_operations *debug_fops)
  1595. {
  1596. struct platform_device *dsidev;
  1597. dsidev = dsi_get_dsidev_from_id(0);
  1598. if (dsidev)
  1599. debugfs_create_file("dsi1_regs", S_IRUGO, debugfs_dir,
  1600. &dsi1_dump_regs, debug_fops);
  1601. dsidev = dsi_get_dsidev_from_id(1);
  1602. if (dsidev)
  1603. debugfs_create_file("dsi2_regs", S_IRUGO, debugfs_dir,
  1604. &dsi2_dump_regs, debug_fops);
  1605. }
  1606. enum dsi_cio_power_state {
  1607. DSI_COMPLEXIO_POWER_OFF = 0x0,
  1608. DSI_COMPLEXIO_POWER_ON = 0x1,
  1609. DSI_COMPLEXIO_POWER_ULPS = 0x2,
  1610. };
  1611. static int dsi_cio_power(struct platform_device *dsidev,
  1612. enum dsi_cio_power_state state)
  1613. {
  1614. int t = 0;
  1615. /* PWR_CMD */
  1616. REG_FLD_MOD(dsidev, DSI_COMPLEXIO_CFG1, state, 28, 27);
  1617. /* PWR_STATUS */
  1618. while (FLD_GET(dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG1),
  1619. 26, 25) != state) {
  1620. if (++t > 1000) {
  1621. DSSERR("failed to set complexio power state to "
  1622. "%d\n", state);
  1623. return -ENODEV;
  1624. }
  1625. udelay(1);
  1626. }
  1627. return 0;
  1628. }
  1629. /* Number of data lanes present on DSI interface */
  1630. static inline int dsi_get_num_data_lanes(struct platform_device *dsidev)
  1631. {
  1632. /* DSI on OMAP3 doesn't have register DSI_GNQ, set number
  1633. * of data lanes as 2 by default */
  1634. if (dss_has_feature(FEAT_DSI_GNQ))
  1635. return REG_GET(dsidev, DSI_GNQ, 11, 9); /* NB_DATA_LANES */
  1636. else
  1637. return 2;
  1638. }
  1639. /* Number of data lanes used by the dss device */
  1640. static inline int dsi_get_num_data_lanes_dssdev(struct omap_dss_device *dssdev)
  1641. {
  1642. int num_data_lanes = 0;
  1643. if (dssdev->phy.dsi.data1_lane != 0)
  1644. num_data_lanes++;
  1645. if (dssdev->phy.dsi.data2_lane != 0)
  1646. num_data_lanes++;
  1647. if (dssdev->phy.dsi.data3_lane != 0)
  1648. num_data_lanes++;
  1649. if (dssdev->phy.dsi.data4_lane != 0)
  1650. num_data_lanes++;
  1651. return num_data_lanes;
  1652. }
  1653. static unsigned dsi_get_line_buf_size(struct platform_device *dsidev)
  1654. {
  1655. int val;
  1656. /* line buffer on OMAP3 is 1024 x 24bits */
  1657. /* XXX: for some reason using full buffer size causes
  1658. * considerable TX slowdown with update sizes that fill the
  1659. * whole buffer */
  1660. if (!dss_has_feature(FEAT_DSI_GNQ))
  1661. return 1023 * 3;
  1662. val = REG_GET(dsidev, DSI_GNQ, 14, 12); /* VP1_LINE_BUFFER_SIZE */
  1663. switch (val) {
  1664. case 1:
  1665. return 512 * 3; /* 512x24 bits */
  1666. case 2:
  1667. return 682 * 3; /* 682x24 bits */
  1668. case 3:
  1669. return 853 * 3; /* 853x24 bits */
  1670. case 4:
  1671. return 1024 * 3; /* 1024x24 bits */
  1672. case 5:
  1673. return 1194 * 3; /* 1194x24 bits */
  1674. case 6:
  1675. return 1365 * 3; /* 1365x24 bits */
  1676. default:
  1677. BUG();
  1678. }
  1679. }
  1680. static void dsi_set_lane_config(struct omap_dss_device *dssdev)
  1681. {
  1682. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  1683. u32 r;
  1684. int num_data_lanes_dssdev = dsi_get_num_data_lanes_dssdev(dssdev);
  1685. int clk_lane = dssdev->phy.dsi.clk_lane;
  1686. int data1_lane = dssdev->phy.dsi.data1_lane;
  1687. int data2_lane = dssdev->phy.dsi.data2_lane;
  1688. int clk_pol = dssdev->phy.dsi.clk_pol;
  1689. int data1_pol = dssdev->phy.dsi.data1_pol;
  1690. int data2_pol = dssdev->phy.dsi.data2_pol;
  1691. r = dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG1);
  1692. r = FLD_MOD(r, clk_lane, 2, 0);
  1693. r = FLD_MOD(r, clk_pol, 3, 3);
  1694. r = FLD_MOD(r, data1_lane, 6, 4);
  1695. r = FLD_MOD(r, data1_pol, 7, 7);
  1696. r = FLD_MOD(r, data2_lane, 10, 8);
  1697. r = FLD_MOD(r, data2_pol, 11, 11);
  1698. if (num_data_lanes_dssdev > 2) {
  1699. int data3_lane = dssdev->phy.dsi.data3_lane;
  1700. int data3_pol = dssdev->phy.dsi.data3_pol;
  1701. r = FLD_MOD(r, data3_lane, 14, 12);
  1702. r = FLD_MOD(r, data3_pol, 15, 15);
  1703. }
  1704. if (num_data_lanes_dssdev > 3) {
  1705. int data4_lane = dssdev->phy.dsi.data4_lane;
  1706. int data4_pol = dssdev->phy.dsi.data4_pol;
  1707. r = FLD_MOD(r, data4_lane, 18, 16);
  1708. r = FLD_MOD(r, data4_pol, 19, 19);
  1709. }
  1710. dsi_write_reg(dsidev, DSI_COMPLEXIO_CFG1, r);
  1711. /* The configuration of the DSI complex I/O (number of data lanes,
  1712. position, differential order) should not be changed while
  1713. DSS.DSI_CLK_CRTRL[20] LP_CLK_ENABLE bit is set to 1. In order for
  1714. the hardware to take into account a new configuration of the complex
  1715. I/O (done in DSS.DSI_COMPLEXIO_CFG1 register), it is recommended to
  1716. follow this sequence: First set the DSS.DSI_CTRL[0] IF_EN bit to 1,
  1717. then reset the DSS.DSI_CTRL[0] IF_EN to 0, then set
  1718. DSS.DSI_CLK_CTRL[20] LP_CLK_ENABLE to 1 and finally set again the
  1719. DSS.DSI_CTRL[0] IF_EN bit to 1. If the sequence is not followed, the
  1720. DSI complex I/O configuration is unknown. */
  1721. /*
  1722. REG_FLD_MOD(dsidev, DSI_CTRL, 1, 0, 0);
  1723. REG_FLD_MOD(dsidev, DSI_CTRL, 0, 0, 0);
  1724. REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 1, 20, 20);
  1725. REG_FLD_MOD(dsidev, DSI_CTRL, 1, 0, 0);
  1726. */
  1727. }
  1728. static inline unsigned ns2ddr(struct platform_device *dsidev, unsigned ns)
  1729. {
  1730. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1731. /* convert time in ns to ddr ticks, rounding up */
  1732. unsigned long ddr_clk = dsi->current_cinfo.clkin4ddr / 4;
  1733. return (ns * (ddr_clk / 1000 / 1000) + 999) / 1000;
  1734. }
  1735. static inline unsigned ddr2ns(struct platform_device *dsidev, unsigned ddr)
  1736. {
  1737. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1738. unsigned long ddr_clk = dsi->current_cinfo.clkin4ddr / 4;
  1739. return ddr * 1000 * 1000 / (ddr_clk / 1000);
  1740. }
  1741. static void dsi_cio_timings(struct platform_device *dsidev)
  1742. {
  1743. u32 r;
  1744. u32 ths_prepare, ths_prepare_ths_zero, ths_trail, ths_exit;
  1745. u32 tlpx_half, tclk_trail, tclk_zero;
  1746. u32 tclk_prepare;
  1747. /* calculate timings */
  1748. /* 1 * DDR_CLK = 2 * UI */
  1749. /* min 40ns + 4*UI max 85ns + 6*UI */
  1750. ths_prepare = ns2ddr(dsidev, 70) + 2;
  1751. /* min 145ns + 10*UI */
  1752. ths_prepare_ths_zero = ns2ddr(dsidev, 175) + 2;
  1753. /* min max(8*UI, 60ns+4*UI) */
  1754. ths_trail = ns2ddr(dsidev, 60) + 5;
  1755. /* min 100ns */
  1756. ths_exit = ns2ddr(dsidev, 145);
  1757. /* tlpx min 50n */
  1758. tlpx_half = ns2ddr(dsidev, 25);
  1759. /* min 60ns */
  1760. tclk_trail = ns2ddr(dsidev, 60) + 2;
  1761. /* min 38ns, max 95ns */
  1762. tclk_prepare = ns2ddr(dsidev, 65);
  1763. /* min tclk-prepare + tclk-zero = 300ns */
  1764. tclk_zero = ns2ddr(dsidev, 260);
  1765. DSSDBG("ths_prepare %u (%uns), ths_prepare_ths_zero %u (%uns)\n",
  1766. ths_prepare, ddr2ns(dsidev, ths_prepare),
  1767. ths_prepare_ths_zero, ddr2ns(dsidev, ths_prepare_ths_zero));
  1768. DSSDBG("ths_trail %u (%uns), ths_exit %u (%uns)\n",
  1769. ths_trail, ddr2ns(dsidev, ths_trail),
  1770. ths_exit, ddr2ns(dsidev, ths_exit));
  1771. DSSDBG("tlpx_half %u (%uns), tclk_trail %u (%uns), "
  1772. "tclk_zero %u (%uns)\n",
  1773. tlpx_half, ddr2ns(dsidev, tlpx_half),
  1774. tclk_trail, ddr2ns(dsidev, tclk_trail),
  1775. tclk_zero, ddr2ns(dsidev, tclk_zero));
  1776. DSSDBG("tclk_prepare %u (%uns)\n",
  1777. tclk_prepare, ddr2ns(dsidev, tclk_prepare));
  1778. /* program timings */
  1779. r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG0);
  1780. r = FLD_MOD(r, ths_prepare, 31, 24);
  1781. r = FLD_MOD(r, ths_prepare_ths_zero, 23, 16);
  1782. r = FLD_MOD(r, ths_trail, 15, 8);
  1783. r = FLD_MOD(r, ths_exit, 7, 0);
  1784. dsi_write_reg(dsidev, DSI_DSIPHY_CFG0, r);
  1785. r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG1);
  1786. r = FLD_MOD(r, tlpx_half, 22, 16);
  1787. r = FLD_MOD(r, tclk_trail, 15, 8);
  1788. r = FLD_MOD(r, tclk_zero, 7, 0);
  1789. dsi_write_reg(dsidev, DSI_DSIPHY_CFG1, r);
  1790. r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG2);
  1791. r = FLD_MOD(r, tclk_prepare, 7, 0);
  1792. dsi_write_reg(dsidev, DSI_DSIPHY_CFG2, r);
  1793. }
  1794. static void dsi_cio_enable_lane_override(struct omap_dss_device *dssdev,
  1795. enum dsi_lane lanes)
  1796. {
  1797. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  1798. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1799. int clk_lane = dssdev->phy.dsi.clk_lane;
  1800. int data1_lane = dssdev->phy.dsi.data1_lane;
  1801. int data2_lane = dssdev->phy.dsi.data2_lane;
  1802. int data3_lane = dssdev->phy.dsi.data3_lane;
  1803. int data4_lane = dssdev->phy.dsi.data4_lane;
  1804. int clk_pol = dssdev->phy.dsi.clk_pol;
  1805. int data1_pol = dssdev->phy.dsi.data1_pol;
  1806. int data2_pol = dssdev->phy.dsi.data2_pol;
  1807. int data3_pol = dssdev->phy.dsi.data3_pol;
  1808. int data4_pol = dssdev->phy.dsi.data4_pol;
  1809. u32 l = 0;
  1810. u8 lptxscp_start = dsi->num_data_lanes == 2 ? 22 : 26;
  1811. if (lanes & DSI_CLK_P)
  1812. l |= 1 << ((clk_lane - 1) * 2 + (clk_pol ? 0 : 1));
  1813. if (lanes & DSI_CLK_N)
  1814. l |= 1 << ((clk_lane - 1) * 2 + (clk_pol ? 1 : 0));
  1815. if (lanes & DSI_DATA1_P)
  1816. l |= 1 << ((data1_lane - 1) * 2 + (data1_pol ? 0 : 1));
  1817. if (lanes & DSI_DATA1_N)
  1818. l |= 1 << ((data1_lane - 1) * 2 + (data1_pol ? 1 : 0));
  1819. if (lanes & DSI_DATA2_P)
  1820. l |= 1 << ((data2_lane - 1) * 2 + (data2_pol ? 0 : 1));
  1821. if (lanes & DSI_DATA2_N)
  1822. l |= 1 << ((data2_lane - 1) * 2 + (data2_pol ? 1 : 0));
  1823. if (lanes & DSI_DATA3_P)
  1824. l |= 1 << ((data3_lane - 1) * 2 + (data3_pol ? 0 : 1));
  1825. if (lanes & DSI_DATA3_N)
  1826. l |= 1 << ((data3_lane - 1) * 2 + (data3_pol ? 1 : 0));
  1827. if (lanes & DSI_DATA4_P)
  1828. l |= 1 << ((data4_lane - 1) * 2 + (data4_pol ? 0 : 1));
  1829. if (lanes & DSI_DATA4_N)
  1830. l |= 1 << ((data4_lane - 1) * 2 + (data4_pol ? 1 : 0));
  1831. /*
  1832. * Bits in REGLPTXSCPDAT4TO0DXDY:
  1833. * 17: DY0 18: DX0
  1834. * 19: DY1 20: DX1
  1835. * 21: DY2 22: DX2
  1836. * 23: DY3 24: DX3
  1837. * 25: DY4 26: DX4
  1838. */
  1839. /* Set the lane override configuration */
  1840. /* REGLPTXSCPDAT4TO0DXDY */
  1841. REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, l, lptxscp_start, 17);
  1842. /* Enable lane override */
  1843. /* ENLPTXSCPDAT */
  1844. REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, 1, 27, 27);
  1845. }
  1846. static void dsi_cio_disable_lane_override(struct platform_device *dsidev)
  1847. {
  1848. /* Disable lane override */
  1849. REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, 0, 27, 27); /* ENLPTXSCPDAT */
  1850. /* Reset the lane override configuration */
  1851. /* REGLPTXSCPDAT4TO0DXDY */
  1852. REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, 0, 22, 17);
  1853. }
  1854. static int dsi_cio_wait_tx_clk_esc_reset(struct omap_dss_device *dssdev)
  1855. {
  1856. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  1857. int t;
  1858. int bits[3];
  1859. bool in_use[3];
  1860. if (dss_has_feature(FEAT_DSI_REVERSE_TXCLKESC)) {
  1861. bits[0] = 28;
  1862. bits[1] = 27;
  1863. bits[2] = 26;
  1864. } else {
  1865. bits[0] = 24;
  1866. bits[1] = 25;
  1867. bits[2] = 26;
  1868. }
  1869. in_use[0] = false;
  1870. in_use[1] = false;
  1871. in_use[2] = false;
  1872. if (dssdev->phy.dsi.clk_lane != 0)
  1873. in_use[dssdev->phy.dsi.clk_lane - 1] = true;
  1874. if (dssdev->phy.dsi.data1_lane != 0)
  1875. in_use[dssdev->phy.dsi.data1_lane - 1] = true;
  1876. if (dssdev->phy.dsi.data2_lane != 0)
  1877. in_use[dssdev->phy.dsi.data2_lane - 1] = true;
  1878. t = 100000;
  1879. while (true) {
  1880. u32 l;
  1881. int i;
  1882. int ok;
  1883. l = dsi_read_reg(dsidev, DSI_DSIPHY_CFG5);
  1884. ok = 0;
  1885. for (i = 0; i < 3; ++i) {
  1886. if (!in_use[i] || (l & (1 << bits[i])))
  1887. ok++;
  1888. }
  1889. if (ok == 3)
  1890. break;
  1891. if (--t == 0) {
  1892. for (i = 0; i < 3; ++i) {
  1893. if (!in_use[i] || (l & (1 << bits[i])))
  1894. continue;
  1895. DSSERR("CIO TXCLKESC%d domain not coming " \
  1896. "out of reset\n", i);
  1897. }
  1898. return -EIO;
  1899. }
  1900. }
  1901. return 0;
  1902. }
  1903. static unsigned dsi_get_lane_mask(struct omap_dss_device *dssdev)
  1904. {
  1905. unsigned lanes = 0;
  1906. if (dssdev->phy.dsi.clk_lane != 0)
  1907. lanes |= 1 << (dssdev->phy.dsi.clk_lane - 1);
  1908. if (dssdev->phy.dsi.data1_lane != 0)
  1909. lanes |= 1 << (dssdev->phy.dsi.data1_lane - 1);
  1910. if (dssdev->phy.dsi.data2_lane != 0)
  1911. lanes |= 1 << (dssdev->phy.dsi.data2_lane - 1);
  1912. if (dssdev->phy.dsi.data3_lane != 0)
  1913. lanes |= 1 << (dssdev->phy.dsi.data3_lane - 1);
  1914. if (dssdev->phy.dsi.data4_lane != 0)
  1915. lanes |= 1 << (dssdev->phy.dsi.data4_lane - 1);
  1916. return lanes;
  1917. }
  1918. static int dsi_cio_init(struct omap_dss_device *dssdev)
  1919. {
  1920. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  1921. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1922. int r;
  1923. int num_data_lanes_dssdev = dsi_get_num_data_lanes_dssdev(dssdev);
  1924. u32 l;
  1925. DSSDBGF();
  1926. r = dsi->enable_pads(dsidev->id, dsi_get_lane_mask(dssdev));
  1927. if (r)
  1928. return r;
  1929. dsi_enable_scp_clk(dsidev);
  1930. /* A dummy read using the SCP interface to any DSIPHY register is
  1931. * required after DSIPHY reset to complete the reset of the DSI complex
  1932. * I/O. */
  1933. dsi_read_reg(dsidev, DSI_DSIPHY_CFG5);
  1934. if (wait_for_bit_change(dsidev, DSI_DSIPHY_CFG5, 30, 1) != 1) {
  1935. DSSERR("CIO SCP Clock domain not coming out of reset.\n");
  1936. r = -EIO;
  1937. goto err_scp_clk_dom;
  1938. }
  1939. dsi_set_lane_config(dssdev);
  1940. /* set TX STOP MODE timer to maximum for this operation */
  1941. l = dsi_read_reg(dsidev, DSI_TIMING1);
  1942. l = FLD_MOD(l, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */
  1943. l = FLD_MOD(l, 1, 14, 14); /* STOP_STATE_X16_IO */
  1944. l = FLD_MOD(l, 1, 13, 13); /* STOP_STATE_X4_IO */
  1945. l = FLD_MOD(l, 0x1fff, 12, 0); /* STOP_STATE_COUNTER_IO */
  1946. dsi_write_reg(dsidev, DSI_TIMING1, l);
  1947. if (dsi->ulps_enabled) {
  1948. u32 lane_mask = DSI_CLK_P | DSI_DATA1_P | DSI_DATA2_P;
  1949. DSSDBG("manual ulps exit\n");
  1950. /* ULPS is exited by Mark-1 state for 1ms, followed by
  1951. * stop state. DSS HW cannot do this via the normal
  1952. * ULPS exit sequence, as after reset the DSS HW thinks
  1953. * that we are not in ULPS mode, and refuses to send the
  1954. * sequence. So we need to send the ULPS exit sequence
  1955. * manually.
  1956. */
  1957. if (num_data_lanes_dssdev > 2)
  1958. lane_mask |= DSI_DATA3_P;
  1959. if (num_data_lanes_dssdev > 3)
  1960. lane_mask |= DSI_DATA4_P;
  1961. dsi_cio_enable_lane_override(dssdev, lane_mask);
  1962. }
  1963. r = dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_ON);
  1964. if (r)
  1965. goto err_cio_pwr;
  1966. if (wait_for_bit_change(dsidev, DSI_COMPLEXIO_CFG1, 29, 1) != 1) {
  1967. DSSERR("CIO PWR clock domain not coming out of reset.\n");
  1968. r = -ENODEV;
  1969. goto err_cio_pwr_dom;
  1970. }
  1971. dsi_if_enable(dsidev, true);
  1972. dsi_if_enable(dsidev, false);
  1973. REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 1, 20, 20); /* LP_CLK_ENABLE */
  1974. r = dsi_cio_wait_tx_clk_esc_reset(dssdev);
  1975. if (r)
  1976. goto err_tx_clk_esc_rst;
  1977. if (dsi->ulps_enabled) {
  1978. /* Keep Mark-1 state for 1ms (as per DSI spec) */
  1979. ktime_t wait = ns_to_ktime(1000 * 1000);
  1980. set_current_state(TASK_UNINTERRUPTIBLE);
  1981. schedule_hrtimeout(&wait, HRTIMER_MODE_REL);
  1982. /* Disable the override. The lanes should be set to Mark-11
  1983. * state by the HW */
  1984. dsi_cio_disable_lane_override(dsidev);
  1985. }
  1986. /* FORCE_TX_STOP_MODE_IO */
  1987. REG_FLD_MOD(dsidev, DSI_TIMING1, 0, 15, 15);
  1988. dsi_cio_timings(dsidev);
  1989. dsi->ulps_enabled = false;
  1990. DSSDBG("CIO init done\n");
  1991. return 0;
  1992. err_tx_clk_esc_rst:
  1993. REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 0, 20, 20); /* LP_CLK_ENABLE */
  1994. err_cio_pwr_dom:
  1995. dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_OFF);
  1996. err_cio_pwr:
  1997. if (dsi->ulps_enabled)
  1998. dsi_cio_disable_lane_override(dsidev);
  1999. err_scp_clk_dom:
  2000. dsi_disable_scp_clk(dsidev);
  2001. dsi->disable_pads(dsidev->id, dsi_get_lane_mask(dssdev));
  2002. return r;
  2003. }
  2004. static void dsi_cio_uninit(struct omap_dss_device *dssdev)
  2005. {
  2006. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  2007. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  2008. dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_OFF);
  2009. dsi_disable_scp_clk(dsidev);
  2010. dsi->disable_pads(dsidev->id, dsi_get_lane_mask(dssdev));
  2011. }
  2012. static void dsi_config_tx_fifo(struct platform_device *dsidev,
  2013. enum fifo_size size1, enum fifo_size size2,
  2014. enum fifo_size size3, enum fifo_size size4)
  2015. {
  2016. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  2017. u32 r = 0;
  2018. int add = 0;
  2019. int i;
  2020. dsi->vc[0].fifo_size = size1;
  2021. dsi->vc[1].fifo_size = size2;
  2022. dsi->vc[2].fifo_size = size3;
  2023. dsi->vc[3].fifo_size = size4;
  2024. for (i = 0; i < 4; i++) {
  2025. u8 v;
  2026. int size = dsi->vc[i].fifo_size;
  2027. if (add + size > 4) {
  2028. DSSERR("Illegal FIFO configuration\n");
  2029. BUG();
  2030. }
  2031. v = FLD_VAL(add, 2, 0) | FLD_VAL(size, 7, 4);
  2032. r |= v << (8 * i);
  2033. /*DSSDBG("TX FIFO vc %d: size %d, add %d\n", i, size, add); */
  2034. add += size;
  2035. }
  2036. dsi_write_reg(dsidev, DSI_TX_FIFO_VC_SIZE, r);
  2037. }
  2038. static void dsi_config_rx_fifo(struct platform_device *dsidev,
  2039. enum fifo_size size1, enum fifo_size size2,
  2040. enum fifo_size size3, enum fifo_size size4)
  2041. {
  2042. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  2043. u32 r = 0;
  2044. int add = 0;
  2045. int i;
  2046. dsi->vc[0].fifo_size = size1;
  2047. dsi->vc[1].fifo_size = size2;
  2048. dsi->vc[2].fifo_size = size3;
  2049. dsi->vc[3].fifo_size = size4;
  2050. for (i = 0; i < 4; i++) {
  2051. u8 v;
  2052. int size = dsi->vc[i].fifo_size;
  2053. if (add + size > 4) {
  2054. DSSERR("Illegal FIFO configuration\n");
  2055. BUG();
  2056. }
  2057. v = FLD_VAL(add, 2, 0) | FLD_VAL(size, 7, 4);
  2058. r |= v << (8 * i);
  2059. /*DSSDBG("RX FIFO vc %d: size %d, add %d\n", i, size, add); */
  2060. add += size;
  2061. }
  2062. dsi_write_reg(dsidev, DSI_RX_FIFO_VC_SIZE, r);
  2063. }
  2064. static int dsi_force_tx_stop_mode_io(struct platform_device *dsidev)
  2065. {
  2066. u32 r;
  2067. r = dsi_read_reg(dsidev, DSI_TIMING1);
  2068. r = FLD_MOD(r, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */
  2069. dsi_write_reg(dsidev, DSI_TIMING1, r);
  2070. if (wait_for_bit_change(dsidev, DSI_TIMING1, 15, 0) != 0) {
  2071. DSSERR("TX_STOP bit not going down\n");
  2072. return -EIO;
  2073. }
  2074. return 0;
  2075. }
  2076. static bool dsi_vc_is_enabled(struct platform_device *dsidev, int channel)
  2077. {
  2078. return REG_GET(dsidev, DSI_VC_CTRL(channel), 0, 0);
  2079. }
  2080. static void dsi_packet_sent_handler_vp(void *data, u32 mask)
  2081. {
  2082. struct dsi_packet_sent_handler_data *vp_data =
  2083. (struct dsi_packet_sent_handler_data *) data;
  2084. struct dsi_data *dsi = dsi_get_dsidrv_data(vp_data->dsidev);
  2085. const int channel = dsi->update_channel;
  2086. u8 bit = dsi->te_enabled ? 30 : 31;
  2087. if (REG_GET(vp_data->dsidev, DSI_VC_TE(channel), bit, bit) == 0)
  2088. complete(vp_data->completion);
  2089. }
  2090. static int dsi_sync_vc_vp(struct platform_device *dsidev, int channel)
  2091. {
  2092. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  2093. DECLARE_COMPLETION_ONSTACK(completion);
  2094. struct dsi_packet_sent_handler_data vp_data = { dsidev, &completion };
  2095. int r = 0;
  2096. u8 bit;
  2097. bit = dsi->te_enabled ? 30 : 31;
  2098. r = dsi_register_isr_vc(dsidev, channel, dsi_packet_sent_handler_vp,
  2099. &vp_data, DSI_VC_IRQ_PACKET_SENT);
  2100. if (r)
  2101. goto err0;
  2102. /* Wait for completion only if TE_EN/TE_START is still set */
  2103. if (REG_GET(dsidev, DSI_VC_TE(channel), bit, bit)) {
  2104. if (wait_for_completion_timeout(&completion,
  2105. msecs_to_jiffies(10)) == 0) {
  2106. DSSERR("Failed to complete previous frame transfer\n");
  2107. r = -EIO;
  2108. goto err1;
  2109. }
  2110. }
  2111. dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_vp,
  2112. &vp_data, DSI_VC_IRQ_PACKET_SENT);
  2113. return 0;
  2114. err1:
  2115. dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_vp,
  2116. &vp_data, DSI_VC_IRQ_PACKET_SENT);
  2117. err0:
  2118. return r;
  2119. }
  2120. static void dsi_packet_sent_handler_l4(void *data, u32 mask)
  2121. {
  2122. struct dsi_packet_sent_handler_data *l4_data =
  2123. (struct dsi_packet_sent_handler_data *) data;
  2124. struct dsi_data *dsi = dsi_get_dsidrv_data(l4_data->dsidev);
  2125. const int channel = dsi->update_channel;
  2126. if (REG_GET(l4_data->dsidev, DSI_VC_CTRL(channel), 5, 5) == 0)
  2127. complete(l4_data->completion);
  2128. }
  2129. static int dsi_sync_vc_l4(struct platform_device *dsidev, int channel)
  2130. {
  2131. DECLARE_COMPLETION_ONSTACK(completion);
  2132. struct dsi_packet_sent_handler_data l4_data = { dsidev, &completion };
  2133. int r = 0;
  2134. r = dsi_register_isr_vc(dsidev, channel, dsi_packet_sent_handler_l4,
  2135. &l4_data, DSI_VC_IRQ_PACKET_SENT);
  2136. if (r)
  2137. goto err0;
  2138. /* Wait for completion only if TX_FIFO_NOT_EMPTY is still set */
  2139. if (REG_GET(dsidev, DSI_VC_CTRL(channel), 5, 5)) {
  2140. if (wait_for_completion_timeout(&completion,
  2141. msecs_to_jiffies(10)) == 0) {
  2142. DSSERR("Failed to complete previous l4 transfer\n");
  2143. r = -EIO;
  2144. goto err1;
  2145. }
  2146. }
  2147. dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_l4,
  2148. &l4_data, DSI_VC_IRQ_PACKET_SENT);
  2149. return 0;
  2150. err1:
  2151. dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_l4,
  2152. &l4_data, DSI_VC_IRQ_PACKET_SENT);
  2153. err0:
  2154. return r;
  2155. }
  2156. static int dsi_sync_vc(struct platform_device *dsidev, int channel)
  2157. {
  2158. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  2159. WARN_ON(!dsi_bus_is_locked(dsidev));
  2160. WARN_ON(in_interrupt());
  2161. if (!dsi_vc_is_enabled(dsidev, channel))
  2162. return 0;
  2163. switch (dsi->vc[channel].source) {
  2164. case DSI_VC_SOURCE_VP:
  2165. return dsi_sync_vc_vp(dsidev, channel);
  2166. case DSI_VC_SOURCE_L4:
  2167. return dsi_sync_vc_l4(dsidev, channel);
  2168. default:
  2169. BUG();
  2170. }
  2171. }
  2172. static int dsi_vc_enable(struct platform_device *dsidev, int channel,
  2173. bool enable)
  2174. {
  2175. DSSDBG("dsi_vc_enable channel %d, enable %d\n",
  2176. channel, enable);
  2177. enable = enable ? 1 : 0;
  2178. REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), enable, 0, 0);
  2179. if (wait_for_bit_change(dsidev, DSI_VC_CTRL(channel),
  2180. 0, enable) != enable) {
  2181. DSSERR("Failed to set dsi_vc_enable to %d\n", enable);
  2182. return -EIO;
  2183. }
  2184. return 0;
  2185. }
  2186. static void dsi_vc_initial_config(struct platform_device *dsidev, int channel)
  2187. {
  2188. u32 r;
  2189. DSSDBGF("%d", channel);
  2190. r = dsi_read_reg(dsidev, DSI_VC_CTRL(channel));
  2191. if (FLD_GET(r, 15, 15)) /* VC_BUSY */
  2192. DSSERR("VC(%d) busy when trying to configure it!\n",
  2193. channel);
  2194. r = FLD_MOD(r, 0, 1, 1); /* SOURCE, 0 = L4 */
  2195. r = FLD_MOD(r, 0, 2, 2); /* BTA_SHORT_EN */
  2196. r = FLD_MOD(r, 0, 3, 3); /* BTA_LONG_EN */
  2197. r = FLD_MOD(r, 0, 4, 4); /* MODE, 0 = command */
  2198. r = FLD_MOD(r, 1, 7, 7); /* CS_TX_EN */
  2199. r = FLD_MOD(r, 1, 8, 8); /* ECC_TX_EN */
  2200. r = FLD_MOD(r, 0, 9, 9); /* MODE_SPEED, high speed on/off */
  2201. if (dss_has_feature(FEAT_DSI_VC_OCP_WIDTH))
  2202. r = FLD_MOD(r, 3, 11, 10); /* OCP_WIDTH = 32 bit */
  2203. r = FLD_MOD(r, 4, 29, 27); /* DMA_RX_REQ_NB = no dma */
  2204. r = FLD_MOD(r, 4, 23, 21); /* DMA_TX_REQ_NB = no dma */
  2205. dsi_write_reg(dsidev, DSI_VC_CTRL(channel), r);
  2206. }
  2207. static int dsi_vc_config_source(struct platform_device *dsidev, int channel,
  2208. enum dsi_vc_source source)
  2209. {
  2210. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  2211. if (dsi->vc[channel].source == source)
  2212. return 0;
  2213. DSSDBGF("%d", channel);
  2214. dsi_sync_vc(dsidev, channel);
  2215. dsi_vc_enable(dsidev, channel, 0);
  2216. /* VC_BUSY */
  2217. if (wait_for_bit_change(dsidev, DSI_VC_CTRL(channel), 15, 0) != 0) {
  2218. DSSERR("vc(%d) busy when trying to config for VP\n", channel);
  2219. return -EIO;
  2220. }
  2221. /* SOURCE, 0 = L4, 1 = video port */
  2222. REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), source, 1, 1);
  2223. /* DCS_CMD_ENABLE */
  2224. if (dss_has_feature(FEAT_DSI_DCS_CMD_CONFIG_VC)) {
  2225. bool enable = source == DSI_VC_SOURCE_VP;
  2226. REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), enable, 30, 30);
  2227. }
  2228. dsi_vc_enable(dsidev, channel, 1);
  2229. dsi->vc[channel].source = source;
  2230. return 0;
  2231. }
  2232. void omapdss_dsi_vc_enable_hs(struct omap_dss_device *dssdev, int channel,
  2233. bool enable)
  2234. {
  2235. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  2236. DSSDBG("dsi_vc_enable_hs(%d, %d)\n", channel, enable);
  2237. WARN_ON(!dsi_bus_is_locked(dsidev));
  2238. dsi_vc_enable(dsidev, channel, 0);
  2239. dsi_if_enable(dsidev, 0);
  2240. REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), enable, 9, 9);
  2241. dsi_vc_enable(dsidev, channel, 1);
  2242. dsi_if_enable(dsidev, 1);
  2243. dsi_force_tx_stop_mode_io(dsidev);
  2244. }
  2245. EXPORT_SYMBOL(omapdss_dsi_vc_enable_hs);
  2246. static void dsi_vc_flush_long_data(struct platform_device *dsidev, int channel)
  2247. {
  2248. while (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) {
  2249. u32 val;
  2250. val = dsi_read_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel));
  2251. DSSDBG("\t\tb1 %#02x b2 %#02x b3 %#02x b4 %#02x\n",
  2252. (val >> 0) & 0xff,
  2253. (val >> 8) & 0xff,
  2254. (val >> 16) & 0xff,
  2255. (val >> 24) & 0xff);
  2256. }
  2257. }
  2258. static void dsi_show_rx_ack_with_err(u16 err)
  2259. {
  2260. DSSERR("\tACK with ERROR (%#x):\n", err);
  2261. if (err & (1 << 0))
  2262. DSSERR("\t\tSoT Error\n");
  2263. if (err & (1 << 1))
  2264. DSSERR("\t\tSoT Sync Error\n");
  2265. if (err & (1 << 2))
  2266. DSSERR("\t\tEoT Sync Error\n");
  2267. if (err & (1 << 3))
  2268. DSSERR("\t\tEscape Mode Entry Command Error\n");
  2269. if (err & (1 << 4))
  2270. DSSERR("\t\tLP Transmit Sync Error\n");
  2271. if (err & (1 << 5))
  2272. DSSERR("\t\tHS Receive Timeout Error\n");
  2273. if (err & (1 << 6))
  2274. DSSERR("\t\tFalse Control Error\n");
  2275. if (err & (1 << 7))
  2276. DSSERR("\t\t(reserved7)\n");
  2277. if (err & (1 << 8))
  2278. DSSERR("\t\tECC Error, single-bit (corrected)\n");
  2279. if (err & (1 << 9))
  2280. DSSERR("\t\tECC Error, multi-bit (not corrected)\n");
  2281. if (err & (1 << 10))
  2282. DSSERR("\t\tChecksum Error\n");
  2283. if (err & (1 << 11))
  2284. DSSERR("\t\tData type not recognized\n");
  2285. if (err & (1 << 12))
  2286. DSSERR("\t\tInvalid VC ID\n");
  2287. if (err & (1 << 13))
  2288. DSSERR("\t\tInvalid Transmission Length\n");
  2289. if (err & (1 << 14))
  2290. DSSERR("\t\t(reserved14)\n");
  2291. if (err & (1 << 15))
  2292. DSSERR("\t\tDSI Protocol Violation\n");
  2293. }
  2294. static u16 dsi_vc_flush_receive_data(struct platform_device *dsidev,
  2295. int channel)
  2296. {
  2297. /* RX_FIFO_NOT_EMPTY */
  2298. while (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) {
  2299. u32 val;
  2300. u8 dt;
  2301. val = dsi_read_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel));
  2302. DSSERR("\trawval %#08x\n", val);
  2303. dt = FLD_GET(val, 5, 0);
  2304. if (dt == MIPI_DSI_RX_ACKNOWLEDGE_AND_ERROR_REPORT) {
  2305. u16 err = FLD_GET(val, 23, 8);
  2306. dsi_show_rx_ack_with_err(err);
  2307. } else if (dt == MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_1BYTE) {
  2308. DSSERR("\tDCS short response, 1 byte: %#x\n",
  2309. FLD_GET(val, 23, 8));
  2310. } else if (dt == MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_2BYTE) {
  2311. DSSERR("\tDCS short response, 2 byte: %#x\n",
  2312. FLD_GET(val, 23, 8));
  2313. } else if (dt == MIPI_DSI_RX_DCS_LONG_READ_RESPONSE) {
  2314. DSSERR("\tDCS long response, len %d\n",
  2315. FLD_GET(val, 23, 8));
  2316. dsi_vc_flush_long_data(dsidev, channel);
  2317. } else {
  2318. DSSERR("\tunknown datatype 0x%02x\n", dt);
  2319. }
  2320. }
  2321. return 0;
  2322. }
  2323. static int dsi_vc_send_bta(struct platform_device *dsidev, int channel)
  2324. {
  2325. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  2326. if (dsi->debug_write || dsi->debug_read)
  2327. DSSDBG("dsi_vc_send_bta %d\n", channel);
  2328. WARN_ON(!dsi_bus_is_locked(dsidev));
  2329. /* RX_FIFO_NOT_EMPTY */
  2330. if (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) {
  2331. DSSERR("rx fifo not empty when sending BTA, dumping data:\n");
  2332. dsi_vc_flush_receive_data(dsidev, channel);
  2333. }
  2334. REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 1, 6, 6); /* BTA_EN */
  2335. return 0;
  2336. }
  2337. int dsi_vc_send_bta_sync(struct omap_dss_device *dssdev, int channel)
  2338. {
  2339. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  2340. DECLARE_COMPLETION_ONSTACK(completion);
  2341. int r = 0;
  2342. u32 err;
  2343. r = dsi_register_isr_vc(dsidev, channel, dsi_completion_handler,
  2344. &completion, DSI_VC_IRQ_BTA);
  2345. if (r)
  2346. goto err0;
  2347. r = dsi_register_isr(dsidev, dsi_completion_handler, &completion,
  2348. DSI_IRQ_ERROR_MASK);
  2349. if (r)
  2350. goto err1;
  2351. r = dsi_vc_send_bta(dsidev, channel);
  2352. if (r)
  2353. goto err2;
  2354. if (wait_for_completion_timeout(&completion,
  2355. msecs_to_jiffies(500)) == 0) {
  2356. DSSERR("Failed to receive BTA\n");
  2357. r = -EIO;
  2358. goto err2;
  2359. }
  2360. err = dsi_get_errors(dsidev);
  2361. if (err) {
  2362. DSSERR("Error while sending BTA: %x\n", err);
  2363. r = -EIO;
  2364. goto err2;
  2365. }
  2366. err2:
  2367. dsi_unregister_isr(dsidev, dsi_completion_handler, &completion,
  2368. DSI_IRQ_ERROR_MASK);
  2369. err1:
  2370. dsi_unregister_isr_vc(dsidev, channel, dsi_completion_handler,
  2371. &completion, DSI_VC_IRQ_BTA);
  2372. err0:
  2373. return r;
  2374. }
  2375. EXPORT_SYMBOL(dsi_vc_send_bta_sync);
  2376. static inline void dsi_vc_write_long_header(struct platform_device *dsidev,
  2377. int channel, u8 data_type, u16 len, u8 ecc)
  2378. {
  2379. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  2380. u32 val;
  2381. u8 data_id;
  2382. WARN_ON(!dsi_bus_is_locked(dsidev));
  2383. data_id = data_type | dsi->vc[channel].vc_id << 6;
  2384. val = FLD_VAL(data_id, 7, 0) | FLD_VAL(len, 23, 8) |
  2385. FLD_VAL(ecc, 31, 24);
  2386. dsi_write_reg(dsidev, DSI_VC_LONG_PACKET_HEADER(channel), val);
  2387. }
  2388. static inline void dsi_vc_write_long_payload(struct platform_device *dsidev,
  2389. int channel, u8 b1, u8 b2, u8 b3, u8 b4)
  2390. {
  2391. u32 val;
  2392. val = b4 << 24 | b3 << 16 | b2 << 8 | b1 << 0;
  2393. /* DSSDBG("\twriting %02x, %02x, %02x, %02x (%#010x)\n",
  2394. b1, b2, b3, b4, val); */
  2395. dsi_write_reg(dsidev, DSI_VC_LONG_PACKET_PAYLOAD(channel), val);
  2396. }
  2397. static int dsi_vc_send_long(struct platform_device *dsidev, int channel,
  2398. u8 data_type, u8 *data, u16 len, u8 ecc)
  2399. {
  2400. /*u32 val; */
  2401. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  2402. int i;
  2403. u8 *p;
  2404. int r = 0;
  2405. u8 b1, b2, b3, b4;
  2406. if (dsi->debug_write)
  2407. DSSDBG("dsi_vc_send_long, %d bytes\n", len);
  2408. /* len + header */
  2409. if (dsi->vc[channel].fifo_size * 32 * 4 < len + 4) {
  2410. DSSERR("unable to send long packet: packet too long.\n");
  2411. return -EINVAL;
  2412. }
  2413. dsi_vc_config_source(dsidev, channel, DSI_VC_SOURCE_L4);
  2414. dsi_vc_write_long_header(dsidev, channel, data_type, len, ecc);
  2415. p = data;
  2416. for (i = 0; i < len >> 2; i++) {
  2417. if (dsi->debug_write)
  2418. DSSDBG("\tsending full packet %d\n", i);
  2419. b1 = *p++;
  2420. b2 = *p++;
  2421. b3 = *p++;
  2422. b4 = *p++;
  2423. dsi_vc_write_long_payload(dsidev, channel, b1, b2, b3, b4);
  2424. }
  2425. i = len % 4;
  2426. if (i) {
  2427. b1 = 0; b2 = 0; b3 = 0;
  2428. if (dsi->debug_write)
  2429. DSSDBG("\tsending remainder bytes %d\n", i);
  2430. switch (i) {
  2431. case 3:
  2432. b1 = *p++;
  2433. b2 = *p++;
  2434. b3 = *p++;
  2435. break;
  2436. case 2:
  2437. b1 = *p++;
  2438. b2 = *p++;
  2439. break;
  2440. case 1:
  2441. b1 = *p++;
  2442. break;
  2443. }
  2444. dsi_vc_write_long_payload(dsidev, channel, b1, b2, b3, 0);
  2445. }
  2446. return r;
  2447. }
  2448. static int dsi_vc_send_short(struct platform_device *dsidev, int channel,
  2449. u8 data_type, u16 data, u8 ecc)
  2450. {
  2451. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  2452. u32 r;
  2453. u8 data_id;
  2454. WARN_ON(!dsi_bus_is_locked(dsidev));
  2455. if (dsi->debug_write)
  2456. DSSDBG("dsi_vc_send_short(ch%d, dt %#x, b1 %#x, b2 %#x)\n",
  2457. channel,
  2458. data_type, data & 0xff, (data >> 8) & 0xff);
  2459. dsi_vc_config_source(dsidev, channel, DSI_VC_SOURCE_L4);
  2460. if (FLD_GET(dsi_read_reg(dsidev, DSI_VC_CTRL(channel)), 16, 16)) {
  2461. DSSERR("ERROR FIFO FULL, aborting transfer\n");
  2462. return -EINVAL;
  2463. }
  2464. data_id = data_type | dsi->vc[channel].vc_id << 6;
  2465. r = (data_id << 0) | (data << 8) | (ecc << 24);
  2466. dsi_write_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel), r);
  2467. return 0;
  2468. }
  2469. int dsi_vc_send_null(struct omap_dss_device *dssdev, int channel)
  2470. {
  2471. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  2472. u8 nullpkg[] = {0, 0, 0, 0};
  2473. return dsi_vc_send_long(dsidev, channel, MIPI_DSI_NULL_PACKET, nullpkg,
  2474. 4, 0);
  2475. }
  2476. EXPORT_SYMBOL(dsi_vc_send_null);
  2477. int dsi_vc_dcs_write_nosync(struct omap_dss_device *dssdev, int channel,
  2478. u8 *data, int len)
  2479. {
  2480. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  2481. int r;
  2482. BUG_ON(len == 0);
  2483. if (len == 1) {
  2484. r = dsi_vc_send_short(dsidev, channel,
  2485. MIPI_DSI_DCS_SHORT_WRITE, data[0], 0);
  2486. } else if (len == 2) {
  2487. r = dsi_vc_send_short(dsidev, channel,
  2488. MIPI_DSI_DCS_SHORT_WRITE_PARAM,
  2489. data[0] | (data[1] << 8), 0);
  2490. } else {
  2491. /* 0x39 = DCS Long Write */
  2492. r = dsi_vc_send_long(dsidev, channel, MIPI_DSI_DCS_LONG_WRITE,
  2493. data, len, 0);
  2494. }
  2495. return r;
  2496. }
  2497. EXPORT_SYMBOL(dsi_vc_dcs_write_nosync);
  2498. int dsi_vc_dcs_write(struct omap_dss_device *dssdev, int channel, u8 *data,
  2499. int len)
  2500. {
  2501. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  2502. int r;
  2503. r = dsi_vc_dcs_write_nosync(dssdev, channel, data, len);
  2504. if (r)
  2505. goto err;
  2506. r = dsi_vc_send_bta_sync(dssdev, channel);
  2507. if (r)
  2508. goto err;
  2509. /* RX_FIFO_NOT_EMPTY */
  2510. if (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) {
  2511. DSSERR("rx fifo not empty after write, dumping data:\n");
  2512. dsi_vc_flush_receive_data(dsidev, channel);
  2513. r = -EIO;
  2514. goto err;
  2515. }
  2516. return 0;
  2517. err:
  2518. DSSERR("dsi_vc_dcs_write(ch %d, cmd 0x%02x, len %d) failed\n",
  2519. channel, data[0], len);
  2520. return r;
  2521. }
  2522. EXPORT_SYMBOL(dsi_vc_dcs_write);
  2523. int dsi_vc_dcs_write_0(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd)
  2524. {
  2525. return dsi_vc_dcs_write(dssdev, channel, &dcs_cmd, 1);
  2526. }
  2527. EXPORT_SYMBOL(dsi_vc_dcs_write_0);
  2528. int dsi_vc_dcs_write_1(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd,
  2529. u8 param)
  2530. {
  2531. u8 buf[2];
  2532. buf[0] = dcs_cmd;
  2533. buf[1] = param;
  2534. return dsi_vc_dcs_write(dssdev, channel, buf, 2);
  2535. }
  2536. EXPORT_SYMBOL(dsi_vc_dcs_write_1);
  2537. int dsi_vc_dcs_read(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd,
  2538. u8 *buf, int buflen)
  2539. {
  2540. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  2541. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  2542. u32 val;
  2543. u8 dt;
  2544. int r;
  2545. if (dsi->debug_read)
  2546. DSSDBG("dsi_vc_dcs_read(ch%d, dcs_cmd %x)\n", channel, dcs_cmd);
  2547. r = dsi_vc_send_short(dsidev, channel, MIPI_DSI_DCS_READ, dcs_cmd, 0);
  2548. if (r)
  2549. goto err;
  2550. r = dsi_vc_send_bta_sync(dssdev, channel);
  2551. if (r)
  2552. goto err;
  2553. /* RX_FIFO_NOT_EMPTY */
  2554. if (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20) == 0) {
  2555. DSSERR("RX fifo empty when trying to read.\n");
  2556. r = -EIO;
  2557. goto err;
  2558. }
  2559. val = dsi_read_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel));
  2560. if (dsi->debug_read)
  2561. DSSDBG("\theader: %08x\n", val);
  2562. dt = FLD_GET(val, 5, 0);
  2563. if (dt == MIPI_DSI_RX_ACKNOWLEDGE_AND_ERROR_REPORT) {
  2564. u16 err = FLD_GET(val, 23, 8);
  2565. dsi_show_rx_ack_with_err(err);
  2566. r = -EIO;
  2567. goto err;
  2568. } else if (dt == MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_1BYTE) {
  2569. u8 data = FLD_GET(val, 15, 8);
  2570. if (dsi->debug_read)
  2571. DSSDBG("\tDCS short response, 1 byte: %02x\n", data);
  2572. if (buflen < 1) {
  2573. r = -EIO;
  2574. goto err;
  2575. }
  2576. buf[0] = data;
  2577. return 1;
  2578. } else if (dt == MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_2BYTE) {
  2579. u16 data = FLD_GET(val, 23, 8);
  2580. if (dsi->debug_read)
  2581. DSSDBG("\tDCS short response, 2 byte: %04x\n", data);
  2582. if (buflen < 2) {
  2583. r = -EIO;
  2584. goto err;
  2585. }
  2586. buf[0] = data & 0xff;
  2587. buf[1] = (data >> 8) & 0xff;
  2588. return 2;
  2589. } else if (dt == MIPI_DSI_RX_DCS_LONG_READ_RESPONSE) {
  2590. int w;
  2591. int len = FLD_GET(val, 23, 8);
  2592. if (dsi->debug_read)
  2593. DSSDBG("\tDCS long response, len %d\n", len);
  2594. if (len > buflen) {
  2595. r = -EIO;
  2596. goto err;
  2597. }
  2598. /* two byte checksum ends the packet, not included in len */
  2599. for (w = 0; w < len + 2;) {
  2600. int b;
  2601. val = dsi_read_reg(dsidev,
  2602. DSI_VC_SHORT_PACKET_HEADER(channel));
  2603. if (dsi->debug_read)
  2604. DSSDBG("\t\t%02x %02x %02x %02x\n",
  2605. (val >> 0) & 0xff,
  2606. (val >> 8) & 0xff,
  2607. (val >> 16) & 0xff,
  2608. (val >> 24) & 0xff);
  2609. for (b = 0; b < 4; ++b) {
  2610. if (w < len)
  2611. buf[w] = (val >> (b * 8)) & 0xff;
  2612. /* we discard the 2 byte checksum */
  2613. ++w;
  2614. }
  2615. }
  2616. return len;
  2617. } else {
  2618. DSSERR("\tunknown datatype 0x%02x\n", dt);
  2619. r = -EIO;
  2620. goto err;
  2621. }
  2622. BUG();
  2623. err:
  2624. DSSERR("dsi_vc_dcs_read(ch %d, cmd 0x%02x) failed\n",
  2625. channel, dcs_cmd);
  2626. return r;
  2627. }
  2628. EXPORT_SYMBOL(dsi_vc_dcs_read);
  2629. int dsi_vc_dcs_read_1(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd,
  2630. u8 *data)
  2631. {
  2632. int r;
  2633. r = dsi_vc_dcs_read(dssdev, channel, dcs_cmd, data, 1);
  2634. if (r < 0)
  2635. return r;
  2636. if (r != 1)
  2637. return -EIO;
  2638. return 0;
  2639. }
  2640. EXPORT_SYMBOL(dsi_vc_dcs_read_1);
  2641. int dsi_vc_dcs_read_2(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd,
  2642. u8 *data1, u8 *data2)
  2643. {
  2644. u8 buf[2];
  2645. int r;
  2646. r = dsi_vc_dcs_read(dssdev, channel, dcs_cmd, buf, 2);
  2647. if (r < 0)
  2648. return r;
  2649. if (r != 2)
  2650. return -EIO;
  2651. *data1 = buf[0];
  2652. *data2 = buf[1];
  2653. return 0;
  2654. }
  2655. EXPORT_SYMBOL(dsi_vc_dcs_read_2);
  2656. int dsi_vc_set_max_rx_packet_size(struct omap_dss_device *dssdev, int channel,
  2657. u16 len)
  2658. {
  2659. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  2660. return dsi_vc_send_short(dsidev, channel,
  2661. MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE, len, 0);
  2662. }
  2663. EXPORT_SYMBOL(dsi_vc_set_max_rx_packet_size);
  2664. static int dsi_enter_ulps(struct platform_device *dsidev)
  2665. {
  2666. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  2667. DECLARE_COMPLETION_ONSTACK(completion);
  2668. int r;
  2669. DSSDBGF();
  2670. WARN_ON(!dsi_bus_is_locked(dsidev));
  2671. WARN_ON(dsi->ulps_enabled);
  2672. if (dsi->ulps_enabled)
  2673. return 0;
  2674. if (REG_GET(dsidev, DSI_CLK_CTRL, 13, 13)) {
  2675. DSSERR("DDR_CLK_ALWAYS_ON enabled when entering ULPS\n");
  2676. return -EIO;
  2677. }
  2678. dsi_sync_vc(dsidev, 0);
  2679. dsi_sync_vc(dsidev, 1);
  2680. dsi_sync_vc(dsidev, 2);
  2681. dsi_sync_vc(dsidev, 3);
  2682. dsi_force_tx_stop_mode_io(dsidev);
  2683. dsi_vc_enable(dsidev, 0, false);
  2684. dsi_vc_enable(dsidev, 1, false);
  2685. dsi_vc_enable(dsidev, 2, false);
  2686. dsi_vc_enable(dsidev, 3, false);
  2687. if (REG_GET(dsidev, DSI_COMPLEXIO_CFG2, 16, 16)) { /* HS_BUSY */
  2688. DSSERR("HS busy when enabling ULPS\n");
  2689. return -EIO;
  2690. }
  2691. if (REG_GET(dsidev, DSI_COMPLEXIO_CFG2, 17, 17)) { /* LP_BUSY */
  2692. DSSERR("LP busy when enabling ULPS\n");
  2693. return -EIO;
  2694. }
  2695. r = dsi_register_isr_cio(dsidev, dsi_completion_handler, &completion,
  2696. DSI_CIO_IRQ_ULPSACTIVENOT_ALL0);
  2697. if (r)
  2698. return r;
  2699. /* Assert TxRequestEsc for data lanes and TxUlpsClk for clk lane */
  2700. /* LANEx_ULPS_SIG2 */
  2701. REG_FLD_MOD(dsidev, DSI_COMPLEXIO_CFG2, (1 << 0) | (1 << 1) | (1 << 2),
  2702. 7, 5);
  2703. if (wait_for_completion_timeout(&completion,
  2704. msecs_to_jiffies(1000)) == 0) {
  2705. DSSERR("ULPS enable timeout\n");
  2706. r = -EIO;
  2707. goto err;
  2708. }
  2709. dsi_unregister_isr_cio(dsidev, dsi_completion_handler, &completion,
  2710. DSI_CIO_IRQ_ULPSACTIVENOT_ALL0);
  2711. /* Reset LANEx_ULPS_SIG2 */
  2712. REG_FLD_MOD(dsidev, DSI_COMPLEXIO_CFG2, (0 << 0) | (0 << 1) | (0 << 2),
  2713. 7, 5);
  2714. dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_ULPS);
  2715. dsi_if_enable(dsidev, false);
  2716. dsi->ulps_enabled = true;
  2717. return 0;
  2718. err:
  2719. dsi_unregister_isr_cio(dsidev, dsi_completion_handler, &completion,
  2720. DSI_CIO_IRQ_ULPSACTIVENOT_ALL0);
  2721. return r;
  2722. }
  2723. static void dsi_set_lp_rx_timeout(struct platform_device *dsidev,
  2724. unsigned ticks, bool x4, bool x16)
  2725. {
  2726. unsigned long fck;
  2727. unsigned long total_ticks;
  2728. u32 r;
  2729. BUG_ON(ticks > 0x1fff);
  2730. /* ticks in DSI_FCK */
  2731. fck = dsi_fclk_rate(dsidev);
  2732. r = dsi_read_reg(dsidev, DSI_TIMING2);
  2733. r = FLD_MOD(r, 1, 15, 15); /* LP_RX_TO */
  2734. r = FLD_MOD(r, x16 ? 1 : 0, 14, 14); /* LP_RX_TO_X16 */
  2735. r = FLD_MOD(r, x4 ? 1 : 0, 13, 13); /* LP_RX_TO_X4 */
  2736. r = FLD_MOD(r, ticks, 12, 0); /* LP_RX_COUNTER */
  2737. dsi_write_reg(dsidev, DSI_TIMING2, r);
  2738. total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1);
  2739. DSSDBG("LP_RX_TO %lu ticks (%#x%s%s) = %lu ns\n",
  2740. total_ticks,
  2741. ticks, x4 ? " x4" : "", x16 ? " x16" : "",
  2742. (total_ticks * 1000) / (fck / 1000 / 1000));
  2743. }
  2744. static void dsi_set_ta_timeout(struct platform_device *dsidev, unsigned ticks,
  2745. bool x8, bool x16)
  2746. {
  2747. unsigned long fck;
  2748. unsigned long total_ticks;
  2749. u32 r;
  2750. BUG_ON(ticks > 0x1fff);
  2751. /* ticks in DSI_FCK */
  2752. fck = dsi_fclk_rate(dsidev);
  2753. r = dsi_read_reg(dsidev, DSI_TIMING1);
  2754. r = FLD_MOD(r, 1, 31, 31); /* TA_TO */
  2755. r = FLD_MOD(r, x16 ? 1 : 0, 30, 30); /* TA_TO_X16 */
  2756. r = FLD_MOD(r, x8 ? 1 : 0, 29, 29); /* TA_TO_X8 */
  2757. r = FLD_MOD(r, ticks, 28, 16); /* TA_TO_COUNTER */
  2758. dsi_write_reg(dsidev, DSI_TIMING1, r);
  2759. total_ticks = ticks * (x16 ? 16 : 1) * (x8 ? 8 : 1);
  2760. DSSDBG("TA_TO %lu ticks (%#x%s%s) = %lu ns\n",
  2761. total_ticks,
  2762. ticks, x8 ? " x8" : "", x16 ? " x16" : "",
  2763. (total_ticks * 1000) / (fck / 1000 / 1000));
  2764. }
  2765. static void dsi_set_stop_state_counter(struct platform_device *dsidev,
  2766. unsigned ticks, bool x4, bool x16)
  2767. {
  2768. unsigned long fck;
  2769. unsigned long total_ticks;
  2770. u32 r;
  2771. BUG_ON(ticks > 0x1fff);
  2772. /* ticks in DSI_FCK */
  2773. fck = dsi_fclk_rate(dsidev);
  2774. r = dsi_read_reg(dsidev, DSI_TIMING1);
  2775. r = FLD_MOD(r, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */
  2776. r = FLD_MOD(r, x16 ? 1 : 0, 14, 14); /* STOP_STATE_X16_IO */
  2777. r = FLD_MOD(r, x4 ? 1 : 0, 13, 13); /* STOP_STATE_X4_IO */
  2778. r = FLD_MOD(r, ticks, 12, 0); /* STOP_STATE_COUNTER_IO */
  2779. dsi_write_reg(dsidev, DSI_TIMING1, r);
  2780. total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1);
  2781. DSSDBG("STOP_STATE_COUNTER %lu ticks (%#x%s%s) = %lu ns\n",
  2782. total_ticks,
  2783. ticks, x4 ? " x4" : "", x16 ? " x16" : "",
  2784. (total_ticks * 1000) / (fck / 1000 / 1000));
  2785. }
  2786. static void dsi_set_hs_tx_timeout(struct platform_device *dsidev,
  2787. unsigned ticks, bool x4, bool x16)
  2788. {
  2789. unsigned long fck;
  2790. unsigned long total_ticks;
  2791. u32 r;
  2792. BUG_ON(ticks > 0x1fff);
  2793. /* ticks in TxByteClkHS */
  2794. fck = dsi_get_txbyteclkhs(dsidev);
  2795. r = dsi_read_reg(dsidev, DSI_TIMING2);
  2796. r = FLD_MOD(r, 1, 31, 31); /* HS_TX_TO */
  2797. r = FLD_MOD(r, x16 ? 1 : 0, 30, 30); /* HS_TX_TO_X16 */
  2798. r = FLD_MOD(r, x4 ? 1 : 0, 29, 29); /* HS_TX_TO_X8 (4 really) */
  2799. r = FLD_MOD(r, ticks, 28, 16); /* HS_TX_TO_COUNTER */
  2800. dsi_write_reg(dsidev, DSI_TIMING2, r);
  2801. total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1);
  2802. DSSDBG("HS_TX_TO %lu ticks (%#x%s%s) = %lu ns\n",
  2803. total_ticks,
  2804. ticks, x4 ? " x4" : "", x16 ? " x16" : "",
  2805. (total_ticks * 1000) / (fck / 1000 / 1000));
  2806. }
  2807. static int dsi_proto_config(struct omap_dss_device *dssdev)
  2808. {
  2809. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  2810. u32 r;
  2811. int buswidth = 0;
  2812. dsi_config_tx_fifo(dsidev, DSI_FIFO_SIZE_32,
  2813. DSI_FIFO_SIZE_32,
  2814. DSI_FIFO_SIZE_32,
  2815. DSI_FIFO_SIZE_32);
  2816. dsi_config_rx_fifo(dsidev, DSI_FIFO_SIZE_32,
  2817. DSI_FIFO_SIZE_32,
  2818. DSI_FIFO_SIZE_32,
  2819. DSI_FIFO_SIZE_32);
  2820. /* XXX what values for the timeouts? */
  2821. dsi_set_stop_state_counter(dsidev, 0x1000, false, false);
  2822. dsi_set_ta_timeout(dsidev, 0x1fff, true, true);
  2823. dsi_set_lp_rx_timeout(dsidev, 0x1fff, true, true);
  2824. dsi_set_hs_tx_timeout(dsidev, 0x1fff, true, true);
  2825. switch (dssdev->ctrl.pixel_size) {
  2826. case 16:
  2827. buswidth = 0;
  2828. break;
  2829. case 18:
  2830. buswidth = 1;
  2831. break;
  2832. case 24:
  2833. buswidth = 2;
  2834. break;
  2835. default:
  2836. BUG();
  2837. }
  2838. r = dsi_read_reg(dsidev, DSI_CTRL);
  2839. r = FLD_MOD(r, 1, 1, 1); /* CS_RX_EN */
  2840. r = FLD_MOD(r, 1, 2, 2); /* ECC_RX_EN */
  2841. r = FLD_MOD(r, 1, 3, 3); /* TX_FIFO_ARBITRATION */
  2842. r = FLD_MOD(r, 1, 4, 4); /* VP_CLK_RATIO, always 1, see errata*/
  2843. r = FLD_MOD(r, buswidth, 7, 6); /* VP_DATA_BUS_WIDTH */
  2844. r = FLD_MOD(r, 0, 8, 8); /* VP_CLK_POL */
  2845. r = FLD_MOD(r, 2, 13, 12); /* LINE_BUFFER, 2 lines */
  2846. r = FLD_MOD(r, 1, 14, 14); /* TRIGGER_RESET_MODE */
  2847. r = FLD_MOD(r, 1, 19, 19); /* EOT_ENABLE */
  2848. if (!dss_has_feature(FEAT_DSI_DCS_CMD_CONFIG_VC)) {
  2849. r = FLD_MOD(r, 1, 24, 24); /* DCS_CMD_ENABLE */
  2850. /* DCS_CMD_CODE, 1=start, 0=continue */
  2851. r = FLD_MOD(r, 0, 25, 25);
  2852. }
  2853. dsi_write_reg(dsidev, DSI_CTRL, r);
  2854. dsi_vc_initial_config(dsidev, 0);
  2855. dsi_vc_initial_config(dsidev, 1);
  2856. dsi_vc_initial_config(dsidev, 2);
  2857. dsi_vc_initial_config(dsidev, 3);
  2858. return 0;
  2859. }
  2860. static void dsi_proto_timings(struct omap_dss_device *dssdev)
  2861. {
  2862. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  2863. unsigned tlpx, tclk_zero, tclk_prepare, tclk_trail;
  2864. unsigned tclk_pre, tclk_post;
  2865. unsigned ths_prepare, ths_prepare_ths_zero, ths_zero;
  2866. unsigned ths_trail, ths_exit;
  2867. unsigned ddr_clk_pre, ddr_clk_post;
  2868. unsigned enter_hs_mode_lat, exit_hs_mode_lat;
  2869. unsigned ths_eot;
  2870. u32 r;
  2871. r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG0);
  2872. ths_prepare = FLD_GET(r, 31, 24);
  2873. ths_prepare_ths_zero = FLD_GET(r, 23, 16);
  2874. ths_zero = ths_prepare_ths_zero - ths_prepare;
  2875. ths_trail = FLD_GET(r, 15, 8);
  2876. ths_exit = FLD_GET(r, 7, 0);
  2877. r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG1);
  2878. tlpx = FLD_GET(r, 22, 16) * 2;
  2879. tclk_trail = FLD_GET(r, 15, 8);
  2880. tclk_zero = FLD_GET(r, 7, 0);
  2881. r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG2);
  2882. tclk_prepare = FLD_GET(r, 7, 0);
  2883. /* min 8*UI */
  2884. tclk_pre = 20;
  2885. /* min 60ns + 52*UI */
  2886. tclk_post = ns2ddr(dsidev, 60) + 26;
  2887. ths_eot = DIV_ROUND_UP(4, dsi_get_num_data_lanes_dssdev(dssdev));
  2888. ddr_clk_pre = DIV_ROUND_UP(tclk_pre + tlpx + tclk_zero + tclk_prepare,
  2889. 4);
  2890. ddr_clk_post = DIV_ROUND_UP(tclk_post + ths_trail, 4) + ths_eot;
  2891. BUG_ON(ddr_clk_pre == 0 || ddr_clk_pre > 255);
  2892. BUG_ON(ddr_clk_post == 0 || ddr_clk_post > 255);
  2893. r = dsi_read_reg(dsidev, DSI_CLK_TIMING);
  2894. r = FLD_MOD(r, ddr_clk_pre, 15, 8);
  2895. r = FLD_MOD(r, ddr_clk_post, 7, 0);
  2896. dsi_write_reg(dsidev, DSI_CLK_TIMING, r);
  2897. DSSDBG("ddr_clk_pre %u, ddr_clk_post %u\n",
  2898. ddr_clk_pre,
  2899. ddr_clk_post);
  2900. enter_hs_mode_lat = 1 + DIV_ROUND_UP(tlpx, 4) +
  2901. DIV_ROUND_UP(ths_prepare, 4) +
  2902. DIV_ROUND_UP(ths_zero + 3, 4);
  2903. exit_hs_mode_lat = DIV_ROUND_UP(ths_trail + ths_exit, 4) + 1 + ths_eot;
  2904. r = FLD_VAL(enter_hs_mode_lat, 31, 16) |
  2905. FLD_VAL(exit_hs_mode_lat, 15, 0);
  2906. dsi_write_reg(dsidev, DSI_VM_TIMING7, r);
  2907. DSSDBG("enter_hs_mode_lat %u, exit_hs_mode_lat %u\n",
  2908. enter_hs_mode_lat, exit_hs_mode_lat);
  2909. }
  2910. static void dsi_update_screen_dispc(struct omap_dss_device *dssdev,
  2911. u16 x, u16 y, u16 w, u16 h)
  2912. {
  2913. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  2914. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  2915. unsigned bytespp;
  2916. unsigned bytespl;
  2917. unsigned bytespf;
  2918. unsigned total_len;
  2919. unsigned packet_payload;
  2920. unsigned packet_len;
  2921. u32 l;
  2922. int r;
  2923. const unsigned channel = dsi->update_channel;
  2924. const unsigned line_buf_size = dsi_get_line_buf_size(dsidev);
  2925. DSSDBG("dsi_update_screen_dispc(%d,%d %dx%d)\n",
  2926. x, y, w, h);
  2927. dsi_vc_config_source(dsidev, channel, DSI_VC_SOURCE_VP);
  2928. bytespp = dssdev->ctrl.pixel_size / 8;
  2929. bytespl = w * bytespp;
  2930. bytespf = bytespl * h;
  2931. /* NOTE: packet_payload has to be equal to N * bytespl, where N is
  2932. * number of lines in a packet. See errata about VP_CLK_RATIO */
  2933. if (bytespf < line_buf_size)
  2934. packet_payload = bytespf;
  2935. else
  2936. packet_payload = (line_buf_size) / bytespl * bytespl;
  2937. packet_len = packet_payload + 1; /* 1 byte for DCS cmd */
  2938. total_len = (bytespf / packet_payload) * packet_len;
  2939. if (bytespf % packet_payload)
  2940. total_len += (bytespf % packet_payload) + 1;
  2941. l = FLD_VAL(total_len, 23, 0); /* TE_SIZE */
  2942. dsi_write_reg(dsidev, DSI_VC_TE(channel), l);
  2943. dsi_vc_write_long_header(dsidev, channel, MIPI_DSI_DCS_LONG_WRITE,
  2944. packet_len, 0);
  2945. if (dsi->te_enabled)
  2946. l = FLD_MOD(l, 1, 30, 30); /* TE_EN */
  2947. else
  2948. l = FLD_MOD(l, 1, 31, 31); /* TE_START */
  2949. dsi_write_reg(dsidev, DSI_VC_TE(channel), l);
  2950. /* We put SIDLEMODE to no-idle for the duration of the transfer,
  2951. * because DSS interrupts are not capable of waking up the CPU and the
  2952. * framedone interrupt could be delayed for quite a long time. I think
  2953. * the same goes for any DSS interrupts, but for some reason I have not
  2954. * seen the problem anywhere else than here.
  2955. */
  2956. dispc_disable_sidle();
  2957. dsi_perf_mark_start(dsidev);
  2958. r = schedule_delayed_work(&dsi->framedone_timeout_work,
  2959. msecs_to_jiffies(250));
  2960. BUG_ON(r == 0);
  2961. dss_start_update(dssdev);
  2962. if (dsi->te_enabled) {
  2963. /* disable LP_RX_TO, so that we can receive TE. Time to wait
  2964. * for TE is longer than the timer allows */
  2965. REG_FLD_MOD(dsidev, DSI_TIMING2, 0, 15, 15); /* LP_RX_TO */
  2966. dsi_vc_send_bta(dsidev, channel);
  2967. #ifdef DSI_CATCH_MISSING_TE
  2968. mod_timer(&dsi->te_timer, jiffies + msecs_to_jiffies(250));
  2969. #endif
  2970. }
  2971. }
  2972. #ifdef DSI_CATCH_MISSING_TE
  2973. static void dsi_te_timeout(unsigned long arg)
  2974. {
  2975. DSSERR("TE not received for 250ms!\n");
  2976. }
  2977. #endif
  2978. static void dsi_handle_framedone(struct platform_device *dsidev, int error)
  2979. {
  2980. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  2981. /* SIDLEMODE back to smart-idle */
  2982. dispc_enable_sidle();
  2983. if (dsi->te_enabled) {
  2984. /* enable LP_RX_TO again after the TE */
  2985. REG_FLD_MOD(dsidev, DSI_TIMING2, 1, 15, 15); /* LP_RX_TO */
  2986. }
  2987. dsi->framedone_callback(error, dsi->framedone_data);
  2988. if (!error)
  2989. dsi_perf_show(dsidev, "DISPC");
  2990. }
  2991. static void dsi_framedone_timeout_work_callback(struct work_struct *work)
  2992. {
  2993. struct dsi_data *dsi = container_of(work, struct dsi_data,
  2994. framedone_timeout_work.work);
  2995. /* XXX While extremely unlikely, we could get FRAMEDONE interrupt after
  2996. * 250ms which would conflict with this timeout work. What should be
  2997. * done is first cancel the transfer on the HW, and then cancel the
  2998. * possibly scheduled framedone work. However, cancelling the transfer
  2999. * on the HW is buggy, and would probably require resetting the whole
  3000. * DSI */
  3001. DSSERR("Framedone not received for 250ms!\n");
  3002. dsi_handle_framedone(dsi->pdev, -ETIMEDOUT);
  3003. }
  3004. static void dsi_framedone_irq_callback(void *data, u32 mask)
  3005. {
  3006. struct omap_dss_device *dssdev = (struct omap_dss_device *) data;
  3007. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3008. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3009. /* Note: We get FRAMEDONE when DISPC has finished sending pixels and
  3010. * turns itself off. However, DSI still has the pixels in its buffers,
  3011. * and is sending the data.
  3012. */
  3013. __cancel_delayed_work(&dsi->framedone_timeout_work);
  3014. dsi_handle_framedone(dsidev, 0);
  3015. #ifdef CONFIG_OMAP2_DSS_FAKE_VSYNC
  3016. dispc_fake_vsync_irq();
  3017. #endif
  3018. }
  3019. int omap_dsi_prepare_update(struct omap_dss_device *dssdev,
  3020. u16 *x, u16 *y, u16 *w, u16 *h,
  3021. bool enlarge_update_area)
  3022. {
  3023. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3024. u16 dw, dh;
  3025. dssdev->driver->get_resolution(dssdev, &dw, &dh);
  3026. if (*x > dw || *y > dh)
  3027. return -EINVAL;
  3028. if (*x + *w > dw)
  3029. return -EINVAL;
  3030. if (*y + *h > dh)
  3031. return -EINVAL;
  3032. if (*w == 1)
  3033. return -EINVAL;
  3034. if (*w == 0 || *h == 0)
  3035. return -EINVAL;
  3036. dsi_perf_mark_setup(dsidev);
  3037. dss_setup_partial_planes(dssdev, x, y, w, h,
  3038. enlarge_update_area);
  3039. dispc_mgr_set_lcd_size(dssdev->manager->id, *w, *h);
  3040. return 0;
  3041. }
  3042. EXPORT_SYMBOL(omap_dsi_prepare_update);
  3043. int omap_dsi_update(struct omap_dss_device *dssdev,
  3044. int channel,
  3045. u16 x, u16 y, u16 w, u16 h,
  3046. void (*callback)(int, void *), void *data)
  3047. {
  3048. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3049. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3050. dsi->update_channel = channel;
  3051. /* OMAP DSS cannot send updates of odd widths.
  3052. * omap_dsi_prepare_update() makes the widths even, but add a BUG_ON
  3053. * here to make sure we catch erroneous updates. Otherwise we'll only
  3054. * see rather obscure HW error happening, as DSS halts. */
  3055. BUG_ON(x % 2 == 1);
  3056. dsi->framedone_callback = callback;
  3057. dsi->framedone_data = data;
  3058. dsi->update_region.x = x;
  3059. dsi->update_region.y = y;
  3060. dsi->update_region.w = w;
  3061. dsi->update_region.h = h;
  3062. dsi->update_region.device = dssdev;
  3063. dsi_update_screen_dispc(dssdev, x, y, w, h);
  3064. return 0;
  3065. }
  3066. EXPORT_SYMBOL(omap_dsi_update);
  3067. /* Display funcs */
  3068. static int dsi_display_init_dispc(struct omap_dss_device *dssdev)
  3069. {
  3070. int r;
  3071. u32 irq;
  3072. irq = dssdev->manager->id == OMAP_DSS_CHANNEL_LCD ?
  3073. DISPC_IRQ_FRAMEDONE : DISPC_IRQ_FRAMEDONE2;
  3074. r = omap_dispc_register_isr(dsi_framedone_irq_callback, (void *) dssdev,
  3075. irq);
  3076. if (r) {
  3077. DSSERR("can't get FRAMEDONE irq\n");
  3078. return r;
  3079. }
  3080. dispc_mgr_set_lcd_display_type(dssdev->manager->id,
  3081. OMAP_DSS_LCD_DISPLAY_TFT);
  3082. dispc_mgr_set_parallel_interface_mode(dssdev->manager->id,
  3083. OMAP_DSS_PARALLELMODE_DSI);
  3084. dispc_mgr_enable_fifohandcheck(dssdev->manager->id, 1);
  3085. dispc_mgr_set_tft_data_lines(dssdev->manager->id,
  3086. dssdev->ctrl.pixel_size);
  3087. {
  3088. struct omap_video_timings timings = {
  3089. .hsw = 1,
  3090. .hfp = 1,
  3091. .hbp = 1,
  3092. .vsw = 1,
  3093. .vfp = 0,
  3094. .vbp = 0,
  3095. };
  3096. dispc_mgr_set_lcd_timings(dssdev->manager->id, &timings);
  3097. }
  3098. return 0;
  3099. }
  3100. static void dsi_display_uninit_dispc(struct omap_dss_device *dssdev)
  3101. {
  3102. u32 irq;
  3103. irq = dssdev->manager->id == OMAP_DSS_CHANNEL_LCD ?
  3104. DISPC_IRQ_FRAMEDONE : DISPC_IRQ_FRAMEDONE2;
  3105. omap_dispc_unregister_isr(dsi_framedone_irq_callback, (void *) dssdev,
  3106. irq);
  3107. }
  3108. static int dsi_configure_dsi_clocks(struct omap_dss_device *dssdev)
  3109. {
  3110. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3111. struct dsi_clock_info cinfo;
  3112. int r;
  3113. /* we always use DSS_CLK_SYSCK as input clock */
  3114. cinfo.use_sys_clk = true;
  3115. cinfo.regn = dssdev->clocks.dsi.regn;
  3116. cinfo.regm = dssdev->clocks.dsi.regm;
  3117. cinfo.regm_dispc = dssdev->clocks.dsi.regm_dispc;
  3118. cinfo.regm_dsi = dssdev->clocks.dsi.regm_dsi;
  3119. r = dsi_calc_clock_rates(dssdev, &cinfo);
  3120. if (r) {
  3121. DSSERR("Failed to calc dsi clocks\n");
  3122. return r;
  3123. }
  3124. r = dsi_pll_set_clock_div(dsidev, &cinfo);
  3125. if (r) {
  3126. DSSERR("Failed to set dsi clocks\n");
  3127. return r;
  3128. }
  3129. return 0;
  3130. }
  3131. static int dsi_configure_dispc_clocks(struct omap_dss_device *dssdev)
  3132. {
  3133. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3134. struct dispc_clock_info dispc_cinfo;
  3135. int r;
  3136. unsigned long long fck;
  3137. fck = dsi_get_pll_hsdiv_dispc_rate(dsidev);
  3138. dispc_cinfo.lck_div = dssdev->clocks.dispc.channel.lck_div;
  3139. dispc_cinfo.pck_div = dssdev->clocks.dispc.channel.pck_div;
  3140. r = dispc_calc_clock_rates(fck, &dispc_cinfo);
  3141. if (r) {
  3142. DSSERR("Failed to calc dispc clocks\n");
  3143. return r;
  3144. }
  3145. r = dispc_mgr_set_clock_div(dssdev->manager->id, &dispc_cinfo);
  3146. if (r) {
  3147. DSSERR("Failed to set dispc clocks\n");
  3148. return r;
  3149. }
  3150. return 0;
  3151. }
  3152. static int dsi_display_init_dsi(struct omap_dss_device *dssdev)
  3153. {
  3154. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3155. int dsi_module = dsi_get_dsidev_id(dsidev);
  3156. int r;
  3157. r = dsi_pll_init(dsidev, true, true);
  3158. if (r)
  3159. goto err0;
  3160. r = dsi_configure_dsi_clocks(dssdev);
  3161. if (r)
  3162. goto err1;
  3163. dss_select_dispc_clk_source(dssdev->clocks.dispc.dispc_fclk_src);
  3164. dss_select_dsi_clk_source(dsi_module, dssdev->clocks.dsi.dsi_fclk_src);
  3165. dss_select_lcd_clk_source(dssdev->manager->id,
  3166. dssdev->clocks.dispc.channel.lcd_clk_src);
  3167. DSSDBG("PLL OK\n");
  3168. r = dsi_configure_dispc_clocks(dssdev);
  3169. if (r)
  3170. goto err2;
  3171. r = dsi_cio_init(dssdev);
  3172. if (r)
  3173. goto err2;
  3174. _dsi_print_reset_status(dsidev);
  3175. dsi_proto_timings(dssdev);
  3176. dsi_set_lp_clk_divisor(dssdev);
  3177. if (1)
  3178. _dsi_print_reset_status(dsidev);
  3179. r = dsi_proto_config(dssdev);
  3180. if (r)
  3181. goto err3;
  3182. /* enable interface */
  3183. dsi_vc_enable(dsidev, 0, 1);
  3184. dsi_vc_enable(dsidev, 1, 1);
  3185. dsi_vc_enable(dsidev, 2, 1);
  3186. dsi_vc_enable(dsidev, 3, 1);
  3187. dsi_if_enable(dsidev, 1);
  3188. dsi_force_tx_stop_mode_io(dsidev);
  3189. return 0;
  3190. err3:
  3191. dsi_cio_uninit(dssdev);
  3192. err2:
  3193. dss_select_dispc_clk_source(OMAP_DSS_CLK_SRC_FCK);
  3194. dss_select_dsi_clk_source(dsi_module, OMAP_DSS_CLK_SRC_FCK);
  3195. dss_select_lcd_clk_source(dssdev->manager->id, OMAP_DSS_CLK_SRC_FCK);
  3196. err1:
  3197. dsi_pll_uninit(dsidev, true);
  3198. err0:
  3199. return r;
  3200. }
  3201. static void dsi_display_uninit_dsi(struct omap_dss_device *dssdev,
  3202. bool disconnect_lanes, bool enter_ulps)
  3203. {
  3204. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3205. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3206. int dsi_module = dsi_get_dsidev_id(dsidev);
  3207. if (enter_ulps && !dsi->ulps_enabled)
  3208. dsi_enter_ulps(dsidev);
  3209. /* disable interface */
  3210. dsi_if_enable(dsidev, 0);
  3211. dsi_vc_enable(dsidev, 0, 0);
  3212. dsi_vc_enable(dsidev, 1, 0);
  3213. dsi_vc_enable(dsidev, 2, 0);
  3214. dsi_vc_enable(dsidev, 3, 0);
  3215. dss_select_dispc_clk_source(OMAP_DSS_CLK_SRC_FCK);
  3216. dss_select_dsi_clk_source(dsi_module, OMAP_DSS_CLK_SRC_FCK);
  3217. dss_select_lcd_clk_source(dssdev->manager->id, OMAP_DSS_CLK_SRC_FCK);
  3218. dsi_cio_uninit(dssdev);
  3219. dsi_pll_uninit(dsidev, disconnect_lanes);
  3220. }
  3221. int omapdss_dsi_display_enable(struct omap_dss_device *dssdev)
  3222. {
  3223. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3224. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3225. int r = 0;
  3226. DSSDBG("dsi_display_enable\n");
  3227. WARN_ON(!dsi_bus_is_locked(dsidev));
  3228. mutex_lock(&dsi->lock);
  3229. if (dssdev->manager == NULL) {
  3230. DSSERR("failed to enable display: no manager\n");
  3231. r = -ENODEV;
  3232. goto err_start_dev;
  3233. }
  3234. r = omap_dss_start_device(dssdev);
  3235. if (r) {
  3236. DSSERR("failed to start device\n");
  3237. goto err_start_dev;
  3238. }
  3239. r = dsi_runtime_get(dsidev);
  3240. if (r)
  3241. goto err_get_dsi;
  3242. dsi_enable_pll_clock(dsidev, 1);
  3243. _dsi_initialize_irq(dsidev);
  3244. r = dsi_display_init_dispc(dssdev);
  3245. if (r)
  3246. goto err_init_dispc;
  3247. r = dsi_display_init_dsi(dssdev);
  3248. if (r)
  3249. goto err_init_dsi;
  3250. mutex_unlock(&dsi->lock);
  3251. return 0;
  3252. err_init_dsi:
  3253. dsi_display_uninit_dispc(dssdev);
  3254. err_init_dispc:
  3255. dsi_enable_pll_clock(dsidev, 0);
  3256. dsi_runtime_put(dsidev);
  3257. err_get_dsi:
  3258. omap_dss_stop_device(dssdev);
  3259. err_start_dev:
  3260. mutex_unlock(&dsi->lock);
  3261. DSSDBG("dsi_display_enable FAILED\n");
  3262. return r;
  3263. }
  3264. EXPORT_SYMBOL(omapdss_dsi_display_enable);
  3265. void omapdss_dsi_display_disable(struct omap_dss_device *dssdev,
  3266. bool disconnect_lanes, bool enter_ulps)
  3267. {
  3268. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3269. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3270. DSSDBG("dsi_display_disable\n");
  3271. WARN_ON(!dsi_bus_is_locked(dsidev));
  3272. mutex_lock(&dsi->lock);
  3273. dsi_sync_vc(dsidev, 0);
  3274. dsi_sync_vc(dsidev, 1);
  3275. dsi_sync_vc(dsidev, 2);
  3276. dsi_sync_vc(dsidev, 3);
  3277. dsi_display_uninit_dispc(dssdev);
  3278. dsi_display_uninit_dsi(dssdev, disconnect_lanes, enter_ulps);
  3279. dsi_runtime_put(dsidev);
  3280. dsi_enable_pll_clock(dsidev, 0);
  3281. omap_dss_stop_device(dssdev);
  3282. mutex_unlock(&dsi->lock);
  3283. }
  3284. EXPORT_SYMBOL(omapdss_dsi_display_disable);
  3285. int omapdss_dsi_enable_te(struct omap_dss_device *dssdev, bool enable)
  3286. {
  3287. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3288. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3289. dsi->te_enabled = enable;
  3290. return 0;
  3291. }
  3292. EXPORT_SYMBOL(omapdss_dsi_enable_te);
  3293. void dsi_get_overlay_fifo_thresholds(enum omap_plane plane,
  3294. u32 fifo_size, u32 burst_size,
  3295. u32 *fifo_low, u32 *fifo_high)
  3296. {
  3297. *fifo_high = fifo_size - burst_size;
  3298. *fifo_low = fifo_size - burst_size * 2;
  3299. }
  3300. int dsi_init_display(struct omap_dss_device *dssdev)
  3301. {
  3302. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3303. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3304. int dsi_module = dsi_get_dsidev_id(dsidev);
  3305. DSSDBG("DSI init\n");
  3306. if (dssdev->panel.dsi_mode == OMAP_DSS_DSI_CMD_MODE) {
  3307. dssdev->caps = OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE |
  3308. OMAP_DSS_DISPLAY_CAP_TEAR_ELIM;
  3309. }
  3310. if (dsi->vdds_dsi_reg == NULL) {
  3311. struct regulator *vdds_dsi;
  3312. vdds_dsi = regulator_get(&dsi->pdev->dev, "vdds_dsi");
  3313. if (IS_ERR(vdds_dsi)) {
  3314. DSSERR("can't get VDDS_DSI regulator\n");
  3315. return PTR_ERR(vdds_dsi);
  3316. }
  3317. dsi->vdds_dsi_reg = vdds_dsi;
  3318. }
  3319. if (dsi_get_num_data_lanes_dssdev(dssdev) > dsi->num_data_lanes) {
  3320. DSSERR("DSI%d can't support more than %d data lanes\n",
  3321. dsi_module + 1, dsi->num_data_lanes);
  3322. return -EINVAL;
  3323. }
  3324. return 0;
  3325. }
  3326. int omap_dsi_request_vc(struct omap_dss_device *dssdev, int *channel)
  3327. {
  3328. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3329. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3330. int i;
  3331. for (i = 0; i < ARRAY_SIZE(dsi->vc); i++) {
  3332. if (!dsi->vc[i].dssdev) {
  3333. dsi->vc[i].dssdev = dssdev;
  3334. *channel = i;
  3335. return 0;
  3336. }
  3337. }
  3338. DSSERR("cannot get VC for display %s", dssdev->name);
  3339. return -ENOSPC;
  3340. }
  3341. EXPORT_SYMBOL(omap_dsi_request_vc);
  3342. int omap_dsi_set_vc_id(struct omap_dss_device *dssdev, int channel, int vc_id)
  3343. {
  3344. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3345. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3346. if (vc_id < 0 || vc_id > 3) {
  3347. DSSERR("VC ID out of range\n");
  3348. return -EINVAL;
  3349. }
  3350. if (channel < 0 || channel > 3) {
  3351. DSSERR("Virtual Channel out of range\n");
  3352. return -EINVAL;
  3353. }
  3354. if (dsi->vc[channel].dssdev != dssdev) {
  3355. DSSERR("Virtual Channel not allocated to display %s\n",
  3356. dssdev->name);
  3357. return -EINVAL;
  3358. }
  3359. dsi->vc[channel].vc_id = vc_id;
  3360. return 0;
  3361. }
  3362. EXPORT_SYMBOL(omap_dsi_set_vc_id);
  3363. void omap_dsi_release_vc(struct omap_dss_device *dssdev, int channel)
  3364. {
  3365. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3366. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3367. if ((channel >= 0 && channel <= 3) &&
  3368. dsi->vc[channel].dssdev == dssdev) {
  3369. dsi->vc[channel].dssdev = NULL;
  3370. dsi->vc[channel].vc_id = 0;
  3371. }
  3372. }
  3373. EXPORT_SYMBOL(omap_dsi_release_vc);
  3374. void dsi_wait_pll_hsdiv_dispc_active(struct platform_device *dsidev)
  3375. {
  3376. if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 7, 1) != 1)
  3377. DSSERR("%s (%s) not active\n",
  3378. dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC),
  3379. dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC));
  3380. }
  3381. void dsi_wait_pll_hsdiv_dsi_active(struct platform_device *dsidev)
  3382. {
  3383. if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 8, 1) != 1)
  3384. DSSERR("%s (%s) not active\n",
  3385. dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI),
  3386. dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI));
  3387. }
  3388. static void dsi_calc_clock_param_ranges(struct platform_device *dsidev)
  3389. {
  3390. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3391. dsi->regn_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGN);
  3392. dsi->regm_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM);
  3393. dsi->regm_dispc_max =
  3394. dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM_DISPC);
  3395. dsi->regm_dsi_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM_DSI);
  3396. dsi->fint_min = dss_feat_get_param_min(FEAT_PARAM_DSIPLL_FINT);
  3397. dsi->fint_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_FINT);
  3398. dsi->lpdiv_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_LPDIV);
  3399. }
  3400. static int dsi_get_clocks(struct platform_device *dsidev)
  3401. {
  3402. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3403. struct clk *clk;
  3404. clk = clk_get(&dsidev->dev, "fck");
  3405. if (IS_ERR(clk)) {
  3406. DSSERR("can't get fck\n");
  3407. return PTR_ERR(clk);
  3408. }
  3409. dsi->dss_clk = clk;
  3410. clk = clk_get(&dsidev->dev, "sys_clk");
  3411. if (IS_ERR(clk)) {
  3412. DSSERR("can't get sys_clk\n");
  3413. clk_put(dsi->dss_clk);
  3414. dsi->dss_clk = NULL;
  3415. return PTR_ERR(clk);
  3416. }
  3417. dsi->sys_clk = clk;
  3418. return 0;
  3419. }
  3420. static void dsi_put_clocks(struct platform_device *dsidev)
  3421. {
  3422. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3423. if (dsi->dss_clk)
  3424. clk_put(dsi->dss_clk);
  3425. if (dsi->sys_clk)
  3426. clk_put(dsi->sys_clk);
  3427. }
  3428. /* DSI1 HW IP initialisation */
  3429. static int omap_dsihw_probe(struct platform_device *dsidev)
  3430. {
  3431. struct omap_display_platform_data *dss_plat_data;
  3432. struct omap_dss_board_info *board_info;
  3433. u32 rev;
  3434. int r, i, dsi_module = dsi_get_dsidev_id(dsidev);
  3435. struct resource *dsi_mem;
  3436. struct dsi_data *dsi;
  3437. dsi = kzalloc(sizeof(*dsi), GFP_KERNEL);
  3438. if (!dsi) {
  3439. r = -ENOMEM;
  3440. goto err_alloc;
  3441. }
  3442. dsi->pdev = dsidev;
  3443. dsi_pdev_map[dsi_module] = dsidev;
  3444. dev_set_drvdata(&dsidev->dev, dsi);
  3445. dss_plat_data = dsidev->dev.platform_data;
  3446. board_info = dss_plat_data->board_data;
  3447. dsi->enable_pads = board_info->dsi_enable_pads;
  3448. dsi->disable_pads = board_info->dsi_disable_pads;
  3449. spin_lock_init(&dsi->irq_lock);
  3450. spin_lock_init(&dsi->errors_lock);
  3451. dsi->errors = 0;
  3452. #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
  3453. spin_lock_init(&dsi->irq_stats_lock);
  3454. dsi->irq_stats.last_reset = jiffies;
  3455. #endif
  3456. mutex_init(&dsi->lock);
  3457. sema_init(&dsi->bus_lock, 1);
  3458. r = dsi_get_clocks(dsidev);
  3459. if (r)
  3460. goto err_get_clk;
  3461. pm_runtime_enable(&dsidev->dev);
  3462. INIT_DELAYED_WORK_DEFERRABLE(&dsi->framedone_timeout_work,
  3463. dsi_framedone_timeout_work_callback);
  3464. #ifdef DSI_CATCH_MISSING_TE
  3465. init_timer(&dsi->te_timer);
  3466. dsi->te_timer.function = dsi_te_timeout;
  3467. dsi->te_timer.data = 0;
  3468. #endif
  3469. dsi_mem = platform_get_resource(dsi->pdev, IORESOURCE_MEM, 0);
  3470. if (!dsi_mem) {
  3471. DSSERR("can't get IORESOURCE_MEM DSI\n");
  3472. r = -EINVAL;
  3473. goto err_ioremap;
  3474. }
  3475. dsi->base = ioremap(dsi_mem->start, resource_size(dsi_mem));
  3476. if (!dsi->base) {
  3477. DSSERR("can't ioremap DSI\n");
  3478. r = -ENOMEM;
  3479. goto err_ioremap;
  3480. }
  3481. dsi->irq = platform_get_irq(dsi->pdev, 0);
  3482. if (dsi->irq < 0) {
  3483. DSSERR("platform_get_irq failed\n");
  3484. r = -ENODEV;
  3485. goto err_get_irq;
  3486. }
  3487. r = request_irq(dsi->irq, omap_dsi_irq_handler, IRQF_SHARED,
  3488. dev_name(&dsidev->dev), dsi->pdev);
  3489. if (r < 0) {
  3490. DSSERR("request_irq failed\n");
  3491. goto err_get_irq;
  3492. }
  3493. /* DSI VCs initialization */
  3494. for (i = 0; i < ARRAY_SIZE(dsi->vc); i++) {
  3495. dsi->vc[i].source = DSI_VC_SOURCE_L4;
  3496. dsi->vc[i].dssdev = NULL;
  3497. dsi->vc[i].vc_id = 0;
  3498. }
  3499. dsi_calc_clock_param_ranges(dsidev);
  3500. r = dsi_runtime_get(dsidev);
  3501. if (r)
  3502. goto err_get_dsi;
  3503. rev = dsi_read_reg(dsidev, DSI_REVISION);
  3504. dev_dbg(&dsidev->dev, "OMAP DSI rev %d.%d\n",
  3505. FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
  3506. dsi->num_data_lanes = dsi_get_num_data_lanes(dsidev);
  3507. dsi_runtime_put(dsidev);
  3508. return 0;
  3509. err_get_dsi:
  3510. free_irq(dsi->irq, dsi->pdev);
  3511. err_get_irq:
  3512. iounmap(dsi->base);
  3513. err_ioremap:
  3514. pm_runtime_disable(&dsidev->dev);
  3515. err_get_clk:
  3516. kfree(dsi);
  3517. err_alloc:
  3518. return r;
  3519. }
  3520. static int omap_dsihw_remove(struct platform_device *dsidev)
  3521. {
  3522. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3523. WARN_ON(dsi->scp_clk_refcount > 0);
  3524. pm_runtime_disable(&dsidev->dev);
  3525. dsi_put_clocks(dsidev);
  3526. if (dsi->vdds_dsi_reg != NULL) {
  3527. if (dsi->vdds_dsi_enabled) {
  3528. regulator_disable(dsi->vdds_dsi_reg);
  3529. dsi->vdds_dsi_enabled = false;
  3530. }
  3531. regulator_put(dsi->vdds_dsi_reg);
  3532. dsi->vdds_dsi_reg = NULL;
  3533. }
  3534. free_irq(dsi->irq, dsi->pdev);
  3535. iounmap(dsi->base);
  3536. kfree(dsi);
  3537. return 0;
  3538. }
  3539. static int dsi_runtime_suspend(struct device *dev)
  3540. {
  3541. dispc_runtime_put();
  3542. dss_runtime_put();
  3543. return 0;
  3544. }
  3545. static int dsi_runtime_resume(struct device *dev)
  3546. {
  3547. int r;
  3548. r = dss_runtime_get();
  3549. if (r)
  3550. goto err_get_dss;
  3551. r = dispc_runtime_get();
  3552. if (r)
  3553. goto err_get_dispc;
  3554. return 0;
  3555. err_get_dispc:
  3556. dss_runtime_put();
  3557. err_get_dss:
  3558. return r;
  3559. }
  3560. static const struct dev_pm_ops dsi_pm_ops = {
  3561. .runtime_suspend = dsi_runtime_suspend,
  3562. .runtime_resume = dsi_runtime_resume,
  3563. };
  3564. static struct platform_driver omap_dsihw_driver = {
  3565. .probe = omap_dsihw_probe,
  3566. .remove = omap_dsihw_remove,
  3567. .driver = {
  3568. .name = "omapdss_dsi",
  3569. .owner = THIS_MODULE,
  3570. .pm = &dsi_pm_ops,
  3571. },
  3572. };
  3573. int dsi_init_platform_driver(void)
  3574. {
  3575. return platform_driver_register(&omap_dsihw_driver);
  3576. }
  3577. void dsi_uninit_platform_driver(void)
  3578. {
  3579. return platform_driver_unregister(&omap_dsihw_driver);
  3580. }