dsi.c 133 KB

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