dsi.c 120 KB

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