dsi.c 137 KB

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