dsi.c 141 KB

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