dsi.c 115 KB

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