dsi.c 122 KB

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