dsi.c 135 KB

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