dsi.c 116 KB

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