dsi.c 138 KB

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