dsi.c 135 KB

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