dsi.c 122 KB

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