dsi.c 132 KB

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