dsi_display.c 207 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2016-2020, The Linux Foundation. All rights reserved.
  4. */
  5. #include <linux/list.h>
  6. #include <linux/of.h>
  7. #include <linux/of_gpio.h>
  8. #include <linux/err.h>
  9. #include "msm_drv.h"
  10. #include "sde_connector.h"
  11. #include "msm_mmu.h"
  12. #include "dsi_display.h"
  13. #include "dsi_panel.h"
  14. #include "dsi_ctrl.h"
  15. #include "dsi_ctrl_hw.h"
  16. #include "dsi_drm.h"
  17. #include "dsi_clk.h"
  18. #include "dsi_pwr.h"
  19. #include "sde_dbg.h"
  20. #include "dsi_parser.h"
  21. #define to_dsi_display(x) container_of(x, struct dsi_display, host)
  22. #define INT_BASE_10 10
  23. #define MISR_BUFF_SIZE 256
  24. #define ESD_MODE_STRING_MAX_LEN 256
  25. #define ESD_TRIGGER_STRING_MAX_LEN 10
  26. #define MAX_NAME_SIZE 64
  27. #define MAX_TE_RECHECKS 5
  28. #define DSI_CLOCK_BITRATE_RADIX 10
  29. #define MAX_TE_SOURCE_ID 2
  30. static char dsi_display_primary[MAX_CMDLINE_PARAM_LEN];
  31. static char dsi_display_secondary[MAX_CMDLINE_PARAM_LEN];
  32. static struct dsi_display_boot_param boot_displays[MAX_DSI_ACTIVE_DISPLAY] = {
  33. {.boot_param = dsi_display_primary},
  34. {.boot_param = dsi_display_secondary},
  35. };
  36. static const struct of_device_id dsi_display_dt_match[] = {
  37. {.compatible = "qcom,dsi-display"},
  38. {}
  39. };
  40. bool is_skip_op_required(struct dsi_display *display)
  41. {
  42. if (!display)
  43. return false;
  44. return (display->is_cont_splash_enabled || display->trusted_vm_env);
  45. }
  46. static void dsi_display_mask_ctrl_error_interrupts(struct dsi_display *display,
  47. u32 mask, bool enable)
  48. {
  49. int i;
  50. struct dsi_display_ctrl *ctrl;
  51. if (!display)
  52. return;
  53. display_for_each_ctrl(i, display) {
  54. ctrl = &display->ctrl[i];
  55. if (!ctrl)
  56. continue;
  57. dsi_ctrl_mask_error_status_interrupts(ctrl->ctrl, mask, enable);
  58. }
  59. }
  60. static int dsi_display_config_clk_gating(struct dsi_display *display,
  61. bool enable)
  62. {
  63. int rc = 0, i = 0;
  64. struct dsi_display_ctrl *mctrl, *ctrl;
  65. enum dsi_clk_gate_type clk_selection;
  66. enum dsi_clk_gate_type const default_clk_select = PIXEL_CLK | DSI_PHY;
  67. if (!display) {
  68. DSI_ERR("Invalid params\n");
  69. return -EINVAL;
  70. }
  71. if (display->panel->host_config.force_hs_clk_lane) {
  72. DSI_DEBUG("no dsi clock gating for continuous clock mode\n");
  73. return 0;
  74. }
  75. mctrl = &display->ctrl[display->clk_master_idx];
  76. if (!mctrl) {
  77. DSI_ERR("Invalid controller\n");
  78. return -EINVAL;
  79. }
  80. clk_selection = display->clk_gating_config;
  81. if (!enable) {
  82. /* for disable path, make sure to disable all clk gating */
  83. clk_selection = DSI_CLK_ALL;
  84. } else if (!clk_selection || clk_selection > DSI_CLK_NONE) {
  85. /* Default selection, no overrides */
  86. clk_selection = default_clk_select;
  87. } else if (clk_selection == DSI_CLK_NONE) {
  88. clk_selection = 0;
  89. }
  90. DSI_DEBUG("%s clock gating Byte:%s Pixel:%s PHY:%s\n",
  91. enable ? "Enabling" : "Disabling",
  92. clk_selection & BYTE_CLK ? "yes" : "no",
  93. clk_selection & PIXEL_CLK ? "yes" : "no",
  94. clk_selection & DSI_PHY ? "yes" : "no");
  95. rc = dsi_ctrl_config_clk_gating(mctrl->ctrl, enable, clk_selection);
  96. if (rc) {
  97. DSI_ERR("[%s] failed to %s clk gating for clocks %d, rc=%d\n",
  98. display->name, enable ? "enable" : "disable",
  99. clk_selection, rc);
  100. return rc;
  101. }
  102. display_for_each_ctrl(i, display) {
  103. ctrl = &display->ctrl[i];
  104. if (!ctrl->ctrl || (ctrl == mctrl))
  105. continue;
  106. /**
  107. * In Split DSI usecase we should not enable clock gating on
  108. * DSI PHY1 to ensure no display atrifacts are seen.
  109. */
  110. clk_selection &= ~DSI_PHY;
  111. rc = dsi_ctrl_config_clk_gating(ctrl->ctrl, enable,
  112. clk_selection);
  113. if (rc) {
  114. DSI_ERR("[%s] failed to %s clk gating for clocks %d, rc=%d\n",
  115. display->name, enable ? "enable" : "disable",
  116. clk_selection, rc);
  117. return rc;
  118. }
  119. }
  120. return 0;
  121. }
  122. static void dsi_display_set_ctrl_esd_check_flag(struct dsi_display *display,
  123. bool enable)
  124. {
  125. int i;
  126. struct dsi_display_ctrl *ctrl;
  127. if (!display)
  128. return;
  129. display_for_each_ctrl(i, display) {
  130. ctrl = &display->ctrl[i];
  131. if (!ctrl)
  132. continue;
  133. ctrl->ctrl->esd_check_underway = enable;
  134. }
  135. }
  136. static void dsi_display_ctrl_irq_update(struct dsi_display *display, bool en)
  137. {
  138. int i;
  139. struct dsi_display_ctrl *ctrl;
  140. if (!display)
  141. return;
  142. display_for_each_ctrl(i, display) {
  143. ctrl = &display->ctrl[i];
  144. if (!ctrl)
  145. continue;
  146. dsi_ctrl_irq_update(ctrl->ctrl, en);
  147. }
  148. }
  149. void dsi_rect_intersect(const struct dsi_rect *r1,
  150. const struct dsi_rect *r2,
  151. struct dsi_rect *result)
  152. {
  153. int l, t, r, b;
  154. if (!r1 || !r2 || !result)
  155. return;
  156. l = max(r1->x, r2->x);
  157. t = max(r1->y, r2->y);
  158. r = min((r1->x + r1->w), (r2->x + r2->w));
  159. b = min((r1->y + r1->h), (r2->y + r2->h));
  160. if (r <= l || b <= t) {
  161. memset(result, 0, sizeof(*result));
  162. } else {
  163. result->x = l;
  164. result->y = t;
  165. result->w = r - l;
  166. result->h = b - t;
  167. }
  168. }
  169. int dsi_display_set_backlight(struct drm_connector *connector,
  170. void *display, u32 bl_lvl)
  171. {
  172. struct dsi_display *dsi_display = display;
  173. struct dsi_panel *panel;
  174. u32 bl_scale, bl_scale_sv;
  175. u64 bl_temp;
  176. int rc = 0;
  177. if (dsi_display == NULL || dsi_display->panel == NULL)
  178. return -EINVAL;
  179. panel = dsi_display->panel;
  180. mutex_lock(&panel->panel_lock);
  181. if (!dsi_panel_initialized(panel)) {
  182. rc = -EINVAL;
  183. goto error;
  184. }
  185. panel->bl_config.bl_level = bl_lvl;
  186. /* scale backlight */
  187. bl_scale = panel->bl_config.bl_scale;
  188. bl_temp = bl_lvl * bl_scale / MAX_BL_SCALE_LEVEL;
  189. bl_scale_sv = panel->bl_config.bl_scale_sv;
  190. bl_temp = (u32)bl_temp * bl_scale_sv / MAX_SV_BL_SCALE_LEVEL;
  191. DSI_DEBUG("bl_scale = %u, bl_scale_sv = %u, bl_lvl = %u\n",
  192. bl_scale, bl_scale_sv, (u32)bl_temp);
  193. rc = dsi_display_clk_ctrl(dsi_display->dsi_clk_handle,
  194. DSI_CORE_CLK, DSI_CLK_ON);
  195. if (rc) {
  196. DSI_ERR("[%s] failed to enable DSI core clocks, rc=%d\n",
  197. dsi_display->name, rc);
  198. goto error;
  199. }
  200. rc = dsi_panel_set_backlight(panel, (u32)bl_temp);
  201. if (rc)
  202. DSI_ERR("unable to set backlight\n");
  203. rc = dsi_display_clk_ctrl(dsi_display->dsi_clk_handle,
  204. DSI_CORE_CLK, DSI_CLK_OFF);
  205. if (rc) {
  206. DSI_ERR("[%s] failed to disable DSI core clocks, rc=%d\n",
  207. dsi_display->name, rc);
  208. goto error;
  209. }
  210. error:
  211. mutex_unlock(&panel->panel_lock);
  212. return rc;
  213. }
  214. static int dsi_display_cmd_engine_enable(struct dsi_display *display)
  215. {
  216. int rc = 0;
  217. int i;
  218. struct dsi_display_ctrl *m_ctrl, *ctrl;
  219. bool skip_op = is_skip_op_required(display);
  220. m_ctrl = &display->ctrl[display->cmd_master_idx];
  221. mutex_lock(&m_ctrl->ctrl->ctrl_lock);
  222. if (display->cmd_engine_refcount > 0) {
  223. display->cmd_engine_refcount++;
  224. goto done;
  225. }
  226. rc = dsi_ctrl_set_cmd_engine_state(m_ctrl->ctrl,
  227. DSI_CTRL_ENGINE_ON, skip_op);
  228. if (rc) {
  229. DSI_ERR("[%s] enable mcmd engine failed, skip_op:%d rc:%d\n",
  230. display->name, skip_op, rc);
  231. goto done;
  232. }
  233. display_for_each_ctrl(i, display) {
  234. ctrl = &display->ctrl[i];
  235. if (!ctrl->ctrl || (ctrl == m_ctrl))
  236. continue;
  237. rc = dsi_ctrl_set_cmd_engine_state(ctrl->ctrl,
  238. DSI_CTRL_ENGINE_ON, skip_op);
  239. if (rc) {
  240. DSI_ERR(
  241. "[%s] enable cmd engine failed, skip_op:%d rc:%d\n",
  242. display->name, skip_op, rc);
  243. goto error_disable_master;
  244. }
  245. }
  246. display->cmd_engine_refcount++;
  247. goto done;
  248. error_disable_master:
  249. (void)dsi_ctrl_set_cmd_engine_state(m_ctrl->ctrl,
  250. DSI_CTRL_ENGINE_OFF, skip_op);
  251. done:
  252. mutex_unlock(&m_ctrl->ctrl->ctrl_lock);
  253. return rc;
  254. }
  255. static int dsi_display_cmd_engine_disable(struct dsi_display *display)
  256. {
  257. int rc = 0;
  258. int i;
  259. struct dsi_display_ctrl *m_ctrl, *ctrl;
  260. bool skip_op = is_skip_op_required(display);
  261. m_ctrl = &display->ctrl[display->cmd_master_idx];
  262. mutex_lock(&m_ctrl->ctrl->ctrl_lock);
  263. if (display->cmd_engine_refcount == 0) {
  264. DSI_ERR("[%s] Invalid refcount\n", display->name);
  265. goto done;
  266. } else if (display->cmd_engine_refcount > 1) {
  267. display->cmd_engine_refcount--;
  268. goto done;
  269. }
  270. display_for_each_ctrl(i, display) {
  271. ctrl = &display->ctrl[i];
  272. if (!ctrl->ctrl || (ctrl == m_ctrl))
  273. continue;
  274. rc = dsi_ctrl_set_cmd_engine_state(ctrl->ctrl,
  275. DSI_CTRL_ENGINE_OFF, skip_op);
  276. if (rc)
  277. DSI_ERR(
  278. "[%s] disable cmd engine failed, skip_op:%d rc:%d\n",
  279. display->name, skip_op, rc);
  280. }
  281. rc = dsi_ctrl_set_cmd_engine_state(m_ctrl->ctrl,
  282. DSI_CTRL_ENGINE_OFF, skip_op);
  283. if (rc) {
  284. DSI_ERR("[%s] disable mcmd engine failed, skip_op:%d rc:%d\n",
  285. display->name, skip_op, rc);
  286. goto error;
  287. }
  288. error:
  289. display->cmd_engine_refcount = 0;
  290. done:
  291. mutex_unlock(&m_ctrl->ctrl->ctrl_lock);
  292. return rc;
  293. }
  294. static void dsi_display_aspace_cb_locked(void *cb_data, bool is_detach)
  295. {
  296. struct dsi_display *display;
  297. struct dsi_display_ctrl *display_ctrl;
  298. int rc, cnt;
  299. if (!cb_data) {
  300. DSI_ERR("aspace cb called with invalid cb_data\n");
  301. return;
  302. }
  303. display = (struct dsi_display *)cb_data;
  304. /*
  305. * acquire panel_lock to make sure no commands are in-progress
  306. * while detaching the non-secure context banks
  307. */
  308. dsi_panel_acquire_panel_lock(display->panel);
  309. if (is_detach) {
  310. /* invalidate the stored iova */
  311. display->cmd_buffer_iova = 0;
  312. /* return the virtual address mapping */
  313. msm_gem_put_vaddr(display->tx_cmd_buf);
  314. msm_gem_vunmap(display->tx_cmd_buf, OBJ_LOCK_NORMAL);
  315. } else {
  316. rc = msm_gem_get_iova(display->tx_cmd_buf,
  317. display->aspace, &(display->cmd_buffer_iova));
  318. if (rc) {
  319. DSI_ERR("failed to get the iova rc %d\n", rc);
  320. goto end;
  321. }
  322. display->vaddr =
  323. (void *) msm_gem_get_vaddr(display->tx_cmd_buf);
  324. if (IS_ERR_OR_NULL(display->vaddr)) {
  325. DSI_ERR("failed to get va rc %d\n", rc);
  326. goto end;
  327. }
  328. }
  329. display_for_each_ctrl(cnt, display) {
  330. display_ctrl = &display->ctrl[cnt];
  331. display_ctrl->ctrl->cmd_buffer_size = display->cmd_buffer_size;
  332. display_ctrl->ctrl->cmd_buffer_iova = display->cmd_buffer_iova;
  333. display_ctrl->ctrl->vaddr = display->vaddr;
  334. display_ctrl->ctrl->secure_mode = is_detach;
  335. }
  336. end:
  337. /* release panel_lock */
  338. dsi_panel_release_panel_lock(display->panel);
  339. }
  340. static irqreturn_t dsi_display_panel_te_irq_handler(int irq, void *data)
  341. {
  342. struct dsi_display *display = (struct dsi_display *)data;
  343. /*
  344. * This irq handler is used for sole purpose of identifying
  345. * ESD attacks on panel and we can safely assume IRQ_HANDLED
  346. * in case of display not being initialized yet
  347. */
  348. if (!display)
  349. return IRQ_HANDLED;
  350. SDE_EVT32(SDE_EVTLOG_FUNC_CASE1);
  351. complete_all(&display->esd_te_gate);
  352. return IRQ_HANDLED;
  353. }
  354. static void dsi_display_change_te_irq_status(struct dsi_display *display,
  355. bool enable)
  356. {
  357. if (!display) {
  358. DSI_ERR("Invalid params\n");
  359. return;
  360. }
  361. /* Handle unbalanced irq enable/disable calls */
  362. if (enable && !display->is_te_irq_enabled) {
  363. enable_irq(gpio_to_irq(display->disp_te_gpio));
  364. display->is_te_irq_enabled = true;
  365. } else if (!enable && display->is_te_irq_enabled) {
  366. disable_irq(gpio_to_irq(display->disp_te_gpio));
  367. display->is_te_irq_enabled = false;
  368. }
  369. }
  370. static void dsi_display_register_te_irq(struct dsi_display *display)
  371. {
  372. int rc = 0;
  373. struct platform_device *pdev;
  374. struct device *dev;
  375. unsigned int te_irq;
  376. pdev = display->pdev;
  377. if (!pdev) {
  378. DSI_ERR("invalid platform device\n");
  379. return;
  380. }
  381. dev = &pdev->dev;
  382. if (!dev) {
  383. DSI_ERR("invalid device\n");
  384. return;
  385. }
  386. if (display->trusted_vm_env) {
  387. DSI_INFO("GPIO's are not enabled in trusted VM\n");
  388. return;
  389. }
  390. if (!gpio_is_valid(display->disp_te_gpio)) {
  391. rc = -EINVAL;
  392. goto error;
  393. }
  394. init_completion(&display->esd_te_gate);
  395. te_irq = gpio_to_irq(display->disp_te_gpio);
  396. /* Avoid deferred spurious irqs with disable_irq() */
  397. irq_set_status_flags(te_irq, IRQ_DISABLE_UNLAZY);
  398. rc = devm_request_irq(dev, te_irq, dsi_display_panel_te_irq_handler,
  399. IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
  400. "TE_GPIO", display);
  401. if (rc) {
  402. DSI_ERR("TE request_irq failed for ESD rc:%d\n", rc);
  403. irq_clear_status_flags(te_irq, IRQ_DISABLE_UNLAZY);
  404. goto error;
  405. }
  406. disable_irq(te_irq);
  407. display->is_te_irq_enabled = false;
  408. return;
  409. error:
  410. /* disable the TE based ESD check */
  411. DSI_WARN("Unable to register for TE IRQ\n");
  412. if (display->panel->esd_config.status_mode == ESD_MODE_PANEL_TE)
  413. display->panel->esd_config.esd_enabled = false;
  414. }
  415. /* Allocate memory for cmd dma tx buffer */
  416. static int dsi_host_alloc_cmd_tx_buffer(struct dsi_display *display)
  417. {
  418. int rc = 0, cnt = 0;
  419. struct dsi_display_ctrl *display_ctrl;
  420. display->tx_cmd_buf = msm_gem_new(display->drm_dev,
  421. SZ_4K,
  422. MSM_BO_UNCACHED);
  423. if ((display->tx_cmd_buf) == NULL) {
  424. DSI_ERR("Failed to allocate cmd tx buf memory\n");
  425. rc = -ENOMEM;
  426. goto error;
  427. }
  428. display->cmd_buffer_size = SZ_4K;
  429. display->aspace = msm_gem_smmu_address_space_get(
  430. display->drm_dev, MSM_SMMU_DOMAIN_UNSECURE);
  431. if (PTR_ERR(display->aspace) == -ENODEV) {
  432. display->aspace = NULL;
  433. DSI_DEBUG("IOMMU not present, relying on VRAM\n");
  434. } else if (IS_ERR_OR_NULL(display->aspace)) {
  435. rc = PTR_ERR(display->aspace);
  436. display->aspace = NULL;
  437. DSI_ERR("failed to get aspace %d\n", rc);
  438. goto free_gem;
  439. } else if (display->aspace) {
  440. /* register to aspace */
  441. rc = msm_gem_address_space_register_cb(display->aspace,
  442. dsi_display_aspace_cb_locked, (void *)display);
  443. if (rc) {
  444. DSI_ERR("failed to register callback %d\n", rc);
  445. goto free_gem;
  446. }
  447. }
  448. rc = msm_gem_get_iova(display->tx_cmd_buf, display->aspace,
  449. &(display->cmd_buffer_iova));
  450. if (rc) {
  451. DSI_ERR("failed to get the iova rc %d\n", rc);
  452. goto free_aspace_cb;
  453. }
  454. display->vaddr =
  455. (void *) msm_gem_get_vaddr(display->tx_cmd_buf);
  456. if (IS_ERR_OR_NULL(display->vaddr)) {
  457. DSI_ERR("failed to get va rc %d\n", rc);
  458. rc = -EINVAL;
  459. goto put_iova;
  460. }
  461. display_for_each_ctrl(cnt, display) {
  462. display_ctrl = &display->ctrl[cnt];
  463. display_ctrl->ctrl->cmd_buffer_size = SZ_4K;
  464. display_ctrl->ctrl->cmd_buffer_iova =
  465. display->cmd_buffer_iova;
  466. display_ctrl->ctrl->vaddr = display->vaddr;
  467. display_ctrl->ctrl->tx_cmd_buf = display->tx_cmd_buf;
  468. }
  469. return rc;
  470. put_iova:
  471. msm_gem_put_iova(display->tx_cmd_buf, display->aspace);
  472. free_aspace_cb:
  473. msm_gem_address_space_unregister_cb(display->aspace,
  474. dsi_display_aspace_cb_locked, display);
  475. free_gem:
  476. mutex_lock(&display->drm_dev->struct_mutex);
  477. msm_gem_free_object(display->tx_cmd_buf);
  478. mutex_unlock(&display->drm_dev->struct_mutex);
  479. error:
  480. return rc;
  481. }
  482. static bool dsi_display_validate_reg_read(struct dsi_panel *panel)
  483. {
  484. int i, j = 0;
  485. int len = 0, *lenp;
  486. int group = 0, count = 0;
  487. struct drm_panel_esd_config *config;
  488. if (!panel)
  489. return false;
  490. config = &(panel->esd_config);
  491. lenp = config->status_valid_params ?: config->status_cmds_rlen;
  492. count = config->status_cmd.count;
  493. for (i = 0; i < count; i++)
  494. len += lenp[i];
  495. for (i = 0; i < len; i++)
  496. j += len;
  497. for (j = 0; j < config->groups; ++j) {
  498. for (i = 0; i < len; ++i) {
  499. if (config->return_buf[i] !=
  500. config->status_value[group + i]) {
  501. DRM_ERROR("mismatch: 0x%x\n",
  502. config->return_buf[i]);
  503. break;
  504. }
  505. }
  506. if (i == len)
  507. return true;
  508. group += len;
  509. }
  510. return false;
  511. }
  512. static void dsi_display_parse_te_data(struct dsi_display *display)
  513. {
  514. struct platform_device *pdev;
  515. struct device *dev;
  516. int rc = 0;
  517. u32 val = 0;
  518. pdev = display->pdev;
  519. if (!pdev) {
  520. DSI_ERR("Invalid platform device\n");
  521. return;
  522. }
  523. dev = &pdev->dev;
  524. if (!dev) {
  525. DSI_ERR("Invalid platform device\n");
  526. return;
  527. }
  528. display->disp_te_gpio = of_get_named_gpio(dev->of_node,
  529. "qcom,platform-te-gpio", 0);
  530. if (display->fw)
  531. rc = dsi_parser_read_u32(display->parser_node,
  532. "qcom,panel-te-source", &val);
  533. else
  534. rc = of_property_read_u32(dev->of_node,
  535. "qcom,panel-te-source", &val);
  536. if (rc || (val > MAX_TE_SOURCE_ID)) {
  537. DSI_ERR("invalid vsync source selection\n");
  538. val = 0;
  539. }
  540. display->te_source = val;
  541. }
  542. static int dsi_display_read_status(struct dsi_display_ctrl *ctrl,
  543. struct dsi_panel *panel)
  544. {
  545. int i, rc = 0, count = 0, start = 0, *lenp;
  546. struct drm_panel_esd_config *config;
  547. struct dsi_cmd_desc *cmds;
  548. u32 flags = 0;
  549. if (!panel || !ctrl || !ctrl->ctrl)
  550. return -EINVAL;
  551. /*
  552. * When DSI controller is not in initialized state, we do not want to
  553. * report a false ESD failure and hence we defer until next read
  554. * happen.
  555. */
  556. if (!dsi_ctrl_validate_host_state(ctrl->ctrl))
  557. return 1;
  558. config = &(panel->esd_config);
  559. lenp = config->status_valid_params ?: config->status_cmds_rlen;
  560. count = config->status_cmd.count;
  561. cmds = config->status_cmd.cmds;
  562. flags |= (DSI_CTRL_CMD_FETCH_MEMORY | DSI_CTRL_CMD_READ);
  563. if (ctrl->ctrl->host_config.panel_mode == DSI_OP_VIDEO_MODE)
  564. flags |= DSI_CTRL_CMD_CUSTOM_DMA_SCHED;
  565. for (i = 0; i < count; ++i) {
  566. memset(config->status_buf, 0x0, SZ_4K);
  567. if (cmds[i].last_command) {
  568. cmds[i].msg.flags |= MIPI_DSI_MSG_LASTCOMMAND;
  569. flags |= DSI_CTRL_CMD_LAST_COMMAND;
  570. }
  571. if ((cmds[i].msg.flags & MIPI_DSI_MSG_CMD_DMA_SCHED) &&
  572. (panel->panel_initialized))
  573. flags |= DSI_CTRL_CMD_CUSTOM_DMA_SCHED;
  574. if (config->status_cmd.state == DSI_CMD_SET_STATE_LP)
  575. cmds[i].msg.flags |= MIPI_DSI_MSG_USE_LPM;
  576. cmds[i].msg.rx_buf = config->status_buf;
  577. cmds[i].msg.rx_len = config->status_cmds_rlen[i];
  578. rc = dsi_ctrl_cmd_transfer(ctrl->ctrl, &cmds[i].msg, &flags);
  579. if (rc <= 0) {
  580. DSI_ERR("rx cmd transfer failed rc=%d\n", rc);
  581. return rc;
  582. }
  583. memcpy(config->return_buf + start,
  584. config->status_buf, lenp[i]);
  585. start += lenp[i];
  586. }
  587. return rc;
  588. }
  589. static int dsi_display_validate_status(struct dsi_display_ctrl *ctrl,
  590. struct dsi_panel *panel)
  591. {
  592. int rc = 0;
  593. rc = dsi_display_read_status(ctrl, panel);
  594. if (rc <= 0) {
  595. goto exit;
  596. } else {
  597. /*
  598. * panel status read successfully.
  599. * check for validity of the data read back.
  600. */
  601. rc = dsi_display_validate_reg_read(panel);
  602. if (!rc) {
  603. rc = -EINVAL;
  604. goto exit;
  605. }
  606. }
  607. exit:
  608. return rc;
  609. }
  610. static int dsi_display_status_reg_read(struct dsi_display *display)
  611. {
  612. int rc = 0, i;
  613. struct dsi_display_ctrl *m_ctrl, *ctrl;
  614. DSI_DEBUG(" ++\n");
  615. m_ctrl = &display->ctrl[display->cmd_master_idx];
  616. if (display->tx_cmd_buf == NULL) {
  617. rc = dsi_host_alloc_cmd_tx_buffer(display);
  618. if (rc) {
  619. DSI_ERR("failed to allocate cmd tx buffer memory\n");
  620. goto done;
  621. }
  622. }
  623. rc = dsi_display_cmd_engine_enable(display);
  624. if (rc) {
  625. DSI_ERR("cmd engine enable failed\n");
  626. return -EPERM;
  627. }
  628. rc = dsi_display_validate_status(m_ctrl, display->panel);
  629. if (rc <= 0) {
  630. DSI_ERR("[%s] read status failed on master,rc=%d\n",
  631. display->name, rc);
  632. goto exit;
  633. }
  634. if (!display->panel->sync_broadcast_en)
  635. goto exit;
  636. display_for_each_ctrl(i, display) {
  637. ctrl = &display->ctrl[i];
  638. if (ctrl == m_ctrl)
  639. continue;
  640. rc = dsi_display_validate_status(ctrl, display->panel);
  641. if (rc <= 0) {
  642. DSI_ERR("[%s] read status failed on slave,rc=%d\n",
  643. display->name, rc);
  644. goto exit;
  645. }
  646. }
  647. exit:
  648. dsi_display_cmd_engine_disable(display);
  649. done:
  650. return rc;
  651. }
  652. static int dsi_display_status_bta_request(struct dsi_display *display)
  653. {
  654. int rc = 0;
  655. DSI_DEBUG(" ++\n");
  656. /* TODO: trigger SW BTA and wait for acknowledgment */
  657. return rc;
  658. }
  659. static int dsi_display_status_check_te(struct dsi_display *display,
  660. int rechecks)
  661. {
  662. int rc = 1, i = 0;
  663. int const esd_te_timeout = msecs_to_jiffies(3*20);
  664. dsi_display_change_te_irq_status(display, true);
  665. for (i = 0; i < rechecks; i++) {
  666. reinit_completion(&display->esd_te_gate);
  667. if (!wait_for_completion_timeout(&display->esd_te_gate,
  668. esd_te_timeout)) {
  669. DSI_ERR("TE check failed\n");
  670. dsi_display_change_te_irq_status(display, false);
  671. return -EINVAL;
  672. }
  673. }
  674. dsi_display_change_te_irq_status(display, false);
  675. return rc;
  676. }
  677. int dsi_display_check_status(struct drm_connector *connector, void *display,
  678. bool te_check_override)
  679. {
  680. struct dsi_display *dsi_display = display;
  681. struct dsi_panel *panel;
  682. u32 status_mode;
  683. int rc = 0x1, ret;
  684. u32 mask;
  685. int te_rechecks = 1;
  686. if (!dsi_display || !dsi_display->panel)
  687. return -EINVAL;
  688. panel = dsi_display->panel;
  689. dsi_panel_acquire_panel_lock(panel);
  690. if (!panel->panel_initialized) {
  691. DSI_DEBUG("Panel not initialized\n");
  692. goto release_panel_lock;
  693. }
  694. /* Prevent another ESD check,when ESD recovery is underway */
  695. if (atomic_read(&panel->esd_recovery_pending))
  696. goto release_panel_lock;
  697. status_mode = panel->esd_config.status_mode;
  698. if (status_mode == ESD_MODE_SW_SIM_SUCCESS)
  699. goto release_panel_lock;
  700. if (status_mode == ESD_MODE_SW_SIM_FAILURE) {
  701. rc = -EINVAL;
  702. goto release_panel_lock;
  703. }
  704. SDE_EVT32(SDE_EVTLOG_FUNC_ENTRY, status_mode, te_check_override);
  705. if (te_check_override)
  706. te_rechecks = MAX_TE_RECHECKS;
  707. ret = dsi_display_clk_ctrl(dsi_display->dsi_clk_handle,
  708. DSI_ALL_CLKS, DSI_CLK_ON);
  709. if (ret)
  710. goto release_panel_lock;
  711. /* Mask error interrupts before attempting ESD read */
  712. mask = BIT(DSI_FIFO_OVERFLOW) | BIT(DSI_FIFO_UNDERFLOW);
  713. dsi_display_set_ctrl_esd_check_flag(dsi_display, true);
  714. dsi_display_mask_ctrl_error_interrupts(dsi_display, mask, true);
  715. if (status_mode == ESD_MODE_REG_READ) {
  716. rc = dsi_display_status_reg_read(dsi_display);
  717. } else if (status_mode == ESD_MODE_SW_BTA) {
  718. rc = dsi_display_status_bta_request(dsi_display);
  719. } else if (status_mode == ESD_MODE_PANEL_TE) {
  720. rc = dsi_display_status_check_te(dsi_display, te_rechecks);
  721. te_check_override = false;
  722. } else {
  723. DSI_WARN("Unsupported check status mode: %d\n", status_mode);
  724. panel->esd_config.esd_enabled = false;
  725. }
  726. if (rc <= 0 && te_check_override)
  727. rc = dsi_display_status_check_te(dsi_display, te_rechecks);
  728. /* Unmask error interrupts if check passed*/
  729. if (rc > 0) {
  730. dsi_display_set_ctrl_esd_check_flag(dsi_display, false);
  731. dsi_display_mask_ctrl_error_interrupts(dsi_display, mask,
  732. false);
  733. if (te_check_override && panel->esd_config.esd_enabled == false)
  734. rc = dsi_display_status_check_te(dsi_display,
  735. te_rechecks);
  736. }
  737. dsi_display_clk_ctrl(dsi_display->dsi_clk_handle,
  738. DSI_ALL_CLKS, DSI_CLK_OFF);
  739. /* Handle Panel failures during display disable sequence */
  740. if (rc <=0)
  741. atomic_set(&panel->esd_recovery_pending, 1);
  742. release_panel_lock:
  743. dsi_panel_release_panel_lock(panel);
  744. SDE_EVT32(SDE_EVTLOG_FUNC_EXIT, rc);
  745. return rc;
  746. }
  747. static int dsi_display_cmd_prepare(const char *cmd_buf, u32 cmd_buf_len,
  748. struct dsi_cmd_desc *cmd, u8 *payload, u32 payload_len)
  749. {
  750. int i;
  751. memset(cmd, 0x00, sizeof(*cmd));
  752. cmd->msg.type = cmd_buf[0];
  753. cmd->last_command = (cmd_buf[1] == 1);
  754. cmd->msg.channel = cmd_buf[2];
  755. cmd->msg.flags = cmd_buf[3];
  756. cmd->msg.ctrl = 0;
  757. cmd->post_wait_ms = cmd->msg.wait_ms = cmd_buf[4];
  758. cmd->msg.tx_len = ((cmd_buf[5] << 8) | (cmd_buf[6]));
  759. if (cmd->msg.tx_len > payload_len) {
  760. DSI_ERR("Incorrect payload length tx_len %zu, payload_len %d\n",
  761. cmd->msg.tx_len, payload_len);
  762. return -EINVAL;
  763. }
  764. if (cmd->last_command)
  765. cmd->msg.flags |= MIPI_DSI_MSG_LASTCOMMAND;
  766. for (i = 0; i < cmd->msg.tx_len; i++)
  767. payload[i] = cmd_buf[7 + i];
  768. cmd->msg.tx_buf = payload;
  769. return 0;
  770. }
  771. static int dsi_display_ctrl_get_host_init_state(struct dsi_display *dsi_display,
  772. bool *state)
  773. {
  774. struct dsi_display_ctrl *ctrl;
  775. int i, rc = -EINVAL;
  776. display_for_each_ctrl(i, dsi_display) {
  777. ctrl = &dsi_display->ctrl[i];
  778. rc = dsi_ctrl_get_host_engine_init_state(ctrl->ctrl, state);
  779. if (rc)
  780. break;
  781. }
  782. return rc;
  783. }
  784. static int dsi_display_cmd_rx(struct dsi_display *display,
  785. struct dsi_cmd_desc *cmd)
  786. {
  787. struct dsi_display_ctrl *m_ctrl = NULL;
  788. u32 mask = 0, flags = 0;
  789. int rc = 0;
  790. if (!display || !display->panel)
  791. return -EINVAL;
  792. m_ctrl = &display->ctrl[display->cmd_master_idx];
  793. if (!m_ctrl || !m_ctrl->ctrl)
  794. return -EINVAL;
  795. /* acquire panel_lock to make sure no commands are in progress */
  796. dsi_panel_acquire_panel_lock(display->panel);
  797. if (!display->panel->panel_initialized) {
  798. DSI_DEBUG("panel not initialized\n");
  799. goto release_panel_lock;
  800. }
  801. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  802. DSI_ALL_CLKS, DSI_CLK_ON);
  803. if (rc)
  804. goto release_panel_lock;
  805. mask = BIT(DSI_FIFO_OVERFLOW) | BIT(DSI_FIFO_UNDERFLOW);
  806. dsi_display_mask_ctrl_error_interrupts(display, mask, true);
  807. rc = dsi_display_cmd_engine_enable(display);
  808. if (rc) {
  809. DSI_ERR("cmd engine enable failed rc = %d\n", rc);
  810. goto error;
  811. }
  812. flags |= (DSI_CTRL_CMD_FETCH_MEMORY | DSI_CTRL_CMD_READ);
  813. if ((m_ctrl->ctrl->host_config.panel_mode == DSI_OP_VIDEO_MODE) ||
  814. ((cmd->msg.flags & MIPI_DSI_MSG_CMD_DMA_SCHED) &&
  815. (display->panel->panel_initialized)))
  816. flags |= DSI_CTRL_CMD_CUSTOM_DMA_SCHED;
  817. rc = dsi_ctrl_cmd_transfer(m_ctrl->ctrl, &cmd->msg, &flags);
  818. if (rc <= 0)
  819. DSI_ERR("rx cmd transfer failed rc = %d\n", rc);
  820. dsi_display_cmd_engine_disable(display);
  821. error:
  822. dsi_display_mask_ctrl_error_interrupts(display, mask, false);
  823. dsi_display_clk_ctrl(display->dsi_clk_handle,
  824. DSI_ALL_CLKS, DSI_CLK_OFF);
  825. release_panel_lock:
  826. dsi_panel_release_panel_lock(display->panel);
  827. return rc;
  828. }
  829. int dsi_display_cmd_transfer(struct drm_connector *connector,
  830. void *display, const char *cmd_buf,
  831. u32 cmd_buf_len)
  832. {
  833. struct dsi_display *dsi_display = display;
  834. struct dsi_cmd_desc cmd;
  835. u8 cmd_payload[MAX_CMD_PAYLOAD_SIZE];
  836. int rc = 0;
  837. bool state = false;
  838. if (!dsi_display || !cmd_buf) {
  839. DSI_ERR("[DSI] invalid params\n");
  840. return -EINVAL;
  841. }
  842. DSI_DEBUG("[DSI] Display command transfer\n");
  843. rc = dsi_display_cmd_prepare(cmd_buf, cmd_buf_len,
  844. &cmd, cmd_payload, MAX_CMD_PAYLOAD_SIZE);
  845. if (rc) {
  846. DSI_ERR("[DSI] command prepare failed. rc %d\n", rc);
  847. return rc;
  848. }
  849. mutex_lock(&dsi_display->display_lock);
  850. rc = dsi_display_ctrl_get_host_init_state(dsi_display, &state);
  851. /**
  852. * Handle scenario where a command transfer is initiated through
  853. * sysfs interface when device is in suepnd state.
  854. */
  855. if (!rc && !state) {
  856. pr_warn_ratelimited("Command xfer attempted while device is in suspend state\n"
  857. );
  858. rc = -EPERM;
  859. goto end;
  860. }
  861. if (rc || !state) {
  862. DSI_ERR("[DSI] Invalid host state %d rc %d\n",
  863. state, rc);
  864. rc = -EPERM;
  865. goto end;
  866. }
  867. rc = dsi_display->host.ops->transfer(&dsi_display->host,
  868. &cmd.msg);
  869. end:
  870. mutex_unlock(&dsi_display->display_lock);
  871. return rc;
  872. }
  873. static void _dsi_display_continuous_clk_ctrl(struct dsi_display *display,
  874. bool enable)
  875. {
  876. int i;
  877. struct dsi_display_ctrl *ctrl;
  878. if (!display || !display->panel->host_config.force_hs_clk_lane)
  879. return;
  880. display_for_each_ctrl(i, display) {
  881. ctrl = &display->ctrl[i];
  882. dsi_ctrl_set_continuous_clk(ctrl->ctrl, enable);
  883. }
  884. }
  885. int dsi_display_cmd_receive(void *display, const char *cmd_buf,
  886. u32 cmd_buf_len, u8 *recv_buf, u32 recv_buf_len)
  887. {
  888. struct dsi_display *dsi_display = display;
  889. struct dsi_cmd_desc cmd = {};
  890. u8 cmd_payload[MAX_CMD_PAYLOAD_SIZE] = {0};
  891. bool state = false;
  892. int rc = -1;
  893. if (!dsi_display || !cmd_buf || !recv_buf) {
  894. DSI_ERR("[DSI] invalid params\n");
  895. return -EINVAL;
  896. }
  897. rc = dsi_display_cmd_prepare(cmd_buf, cmd_buf_len,
  898. &cmd, cmd_payload, MAX_CMD_PAYLOAD_SIZE);
  899. if (rc) {
  900. DSI_ERR("[DSI] command prepare failed, rc = %d\n", rc);
  901. return rc;
  902. }
  903. cmd.msg.rx_buf = recv_buf;
  904. cmd.msg.rx_len = recv_buf_len;
  905. mutex_lock(&dsi_display->display_lock);
  906. rc = dsi_display_ctrl_get_host_init_state(dsi_display, &state);
  907. if (rc || !state) {
  908. DSI_ERR("[DSI] Invalid host state = %d rc = %d\n",
  909. state, rc);
  910. rc = -EPERM;
  911. goto end;
  912. }
  913. rc = dsi_display_cmd_rx(dsi_display, &cmd);
  914. if (rc <= 0)
  915. DSI_ERR("[DSI] Display command receive failed, rc=%d\n", rc);
  916. end:
  917. mutex_unlock(&dsi_display->display_lock);
  918. return rc;
  919. }
  920. int dsi_display_soft_reset(void *display)
  921. {
  922. struct dsi_display *dsi_display;
  923. struct dsi_display_ctrl *ctrl;
  924. int rc = 0;
  925. int i;
  926. if (!display)
  927. return -EINVAL;
  928. dsi_display = display;
  929. display_for_each_ctrl(i, dsi_display) {
  930. ctrl = &dsi_display->ctrl[i];
  931. rc = dsi_ctrl_soft_reset(ctrl->ctrl);
  932. if (rc) {
  933. DSI_ERR("[%s] failed to soft reset host_%d, rc=%d\n",
  934. dsi_display->name, i, rc);
  935. break;
  936. }
  937. }
  938. return rc;
  939. }
  940. enum dsi_pixel_format dsi_display_get_dst_format(
  941. struct drm_connector *connector,
  942. void *display)
  943. {
  944. enum dsi_pixel_format format = DSI_PIXEL_FORMAT_MAX;
  945. struct dsi_display *dsi_display = (struct dsi_display *)display;
  946. if (!dsi_display || !dsi_display->panel) {
  947. DSI_ERR("Invalid params(s) dsi_display %pK, panel %pK\n",
  948. dsi_display,
  949. ((dsi_display) ? dsi_display->panel : NULL));
  950. return format;
  951. }
  952. format = dsi_display->panel->host_config.dst_format;
  953. return format;
  954. }
  955. static void _dsi_display_setup_misr(struct dsi_display *display)
  956. {
  957. int i;
  958. display_for_each_ctrl(i, display) {
  959. dsi_ctrl_setup_misr(display->ctrl[i].ctrl,
  960. display->misr_enable,
  961. display->misr_frame_count);
  962. }
  963. }
  964. int dsi_display_set_power(struct drm_connector *connector,
  965. int power_mode, void *disp)
  966. {
  967. struct dsi_display *display = disp;
  968. int rc = 0;
  969. if (!display || !display->panel) {
  970. DSI_ERR("invalid display/panel\n");
  971. return -EINVAL;
  972. }
  973. switch (power_mode) {
  974. case SDE_MODE_DPMS_LP1:
  975. rc = dsi_panel_set_lp1(display->panel);
  976. break;
  977. case SDE_MODE_DPMS_LP2:
  978. rc = dsi_panel_set_lp2(display->panel);
  979. break;
  980. case SDE_MODE_DPMS_ON:
  981. if ((display->panel->power_mode == SDE_MODE_DPMS_LP1) ||
  982. (display->panel->power_mode == SDE_MODE_DPMS_LP2))
  983. rc = dsi_panel_set_nolp(display->panel);
  984. break;
  985. case SDE_MODE_DPMS_OFF:
  986. default:
  987. return rc;
  988. }
  989. SDE_EVT32(display->panel->power_mode, power_mode, rc);
  990. DSI_DEBUG("Power mode transition from %d to %d %s",
  991. display->panel->power_mode, power_mode,
  992. rc ? "failed" : "successful");
  993. if (!rc)
  994. display->panel->power_mode = power_mode;
  995. return rc;
  996. }
  997. #ifdef CONFIG_DEBUG_FS
  998. static bool dsi_display_is_te_based_esd(struct dsi_display *display)
  999. {
  1000. u32 status_mode = 0;
  1001. if (!display->panel) {
  1002. DSI_ERR("Invalid panel data\n");
  1003. return false;
  1004. }
  1005. status_mode = display->panel->esd_config.status_mode;
  1006. if (status_mode == ESD_MODE_PANEL_TE &&
  1007. gpio_is_valid(display->disp_te_gpio))
  1008. return true;
  1009. return false;
  1010. }
  1011. static ssize_t debugfs_dump_info_read(struct file *file,
  1012. char __user *user_buf,
  1013. size_t user_len,
  1014. loff_t *ppos)
  1015. {
  1016. struct dsi_display *display = file->private_data;
  1017. char *buf;
  1018. u32 len = 0;
  1019. int i;
  1020. if (!display)
  1021. return -ENODEV;
  1022. if (*ppos)
  1023. return 0;
  1024. buf = kzalloc(SZ_4K, GFP_KERNEL);
  1025. if (!buf)
  1026. return -ENOMEM;
  1027. len += snprintf(buf + len, (SZ_4K - len), "name = %s\n", display->name);
  1028. len += snprintf(buf + len, (SZ_4K - len),
  1029. "\tResolution = %dx%d\n",
  1030. display->config.video_timing.h_active,
  1031. display->config.video_timing.v_active);
  1032. display_for_each_ctrl(i, display) {
  1033. len += snprintf(buf + len, (SZ_4K - len),
  1034. "\tCTRL_%d:\n\t\tctrl = %s\n\t\tphy = %s\n",
  1035. i, display->ctrl[i].ctrl->name,
  1036. display->ctrl[i].phy->name);
  1037. }
  1038. len += snprintf(buf + len, (SZ_4K - len),
  1039. "\tPanel = %s\n", display->panel->name);
  1040. len += snprintf(buf + len, (SZ_4K - len),
  1041. "\tClock master = %s\n",
  1042. display->ctrl[display->clk_master_idx].ctrl->name);
  1043. if (len > user_len)
  1044. len = user_len;
  1045. if (copy_to_user(user_buf, buf, len)) {
  1046. kfree(buf);
  1047. return -EFAULT;
  1048. }
  1049. *ppos += len;
  1050. kfree(buf);
  1051. return len;
  1052. }
  1053. static ssize_t debugfs_misr_setup(struct file *file,
  1054. const char __user *user_buf,
  1055. size_t user_len,
  1056. loff_t *ppos)
  1057. {
  1058. struct dsi_display *display = file->private_data;
  1059. char *buf;
  1060. int rc = 0;
  1061. size_t len;
  1062. u32 enable, frame_count;
  1063. if (!display)
  1064. return -ENODEV;
  1065. if (*ppos)
  1066. return 0;
  1067. buf = kzalloc(MISR_BUFF_SIZE, GFP_KERNEL);
  1068. if (!buf)
  1069. return -ENOMEM;
  1070. /* leave room for termination char */
  1071. len = min_t(size_t, user_len, MISR_BUFF_SIZE - 1);
  1072. if (copy_from_user(buf, user_buf, len)) {
  1073. rc = -EINVAL;
  1074. goto error;
  1075. }
  1076. buf[len] = '\0'; /* terminate the string */
  1077. if (sscanf(buf, "%u %u", &enable, &frame_count) != 2) {
  1078. rc = -EINVAL;
  1079. goto error;
  1080. }
  1081. display->misr_enable = enable;
  1082. display->misr_frame_count = frame_count;
  1083. mutex_lock(&display->display_lock);
  1084. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  1085. DSI_CORE_CLK, DSI_CLK_ON);
  1086. if (rc) {
  1087. DSI_ERR("[%s] failed to enable DSI core clocks, rc=%d\n",
  1088. display->name, rc);
  1089. goto unlock;
  1090. }
  1091. _dsi_display_setup_misr(display);
  1092. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  1093. DSI_CORE_CLK, DSI_CLK_OFF);
  1094. if (rc) {
  1095. DSI_ERR("[%s] failed to disable DSI core clocks, rc=%d\n",
  1096. display->name, rc);
  1097. goto unlock;
  1098. }
  1099. rc = user_len;
  1100. unlock:
  1101. mutex_unlock(&display->display_lock);
  1102. error:
  1103. kfree(buf);
  1104. return rc;
  1105. }
  1106. static ssize_t debugfs_misr_read(struct file *file,
  1107. char __user *user_buf,
  1108. size_t user_len,
  1109. loff_t *ppos)
  1110. {
  1111. struct dsi_display *display = file->private_data;
  1112. char *buf;
  1113. u32 len = 0;
  1114. int rc = 0;
  1115. struct dsi_ctrl *dsi_ctrl;
  1116. int i;
  1117. u32 misr;
  1118. size_t max_len = min_t(size_t, user_len, MISR_BUFF_SIZE);
  1119. if (!display)
  1120. return -ENODEV;
  1121. if (*ppos)
  1122. return 0;
  1123. buf = kzalloc(max_len, GFP_KERNEL);
  1124. if (ZERO_OR_NULL_PTR(buf))
  1125. return -ENOMEM;
  1126. mutex_lock(&display->display_lock);
  1127. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  1128. DSI_CORE_CLK, DSI_CLK_ON);
  1129. if (rc) {
  1130. DSI_ERR("[%s] failed to enable DSI core clocks, rc=%d\n",
  1131. display->name, rc);
  1132. goto error;
  1133. }
  1134. display_for_each_ctrl(i, display) {
  1135. dsi_ctrl = display->ctrl[i].ctrl;
  1136. misr = dsi_ctrl_collect_misr(display->ctrl[i].ctrl);
  1137. len += snprintf((buf + len), max_len - len,
  1138. "DSI_%d MISR: 0x%x\n", dsi_ctrl->cell_index, misr);
  1139. if (len >= max_len)
  1140. break;
  1141. }
  1142. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  1143. DSI_CORE_CLK, DSI_CLK_OFF);
  1144. if (rc) {
  1145. DSI_ERR("[%s] failed to disable DSI core clocks, rc=%d\n",
  1146. display->name, rc);
  1147. goto error;
  1148. }
  1149. if (copy_to_user(user_buf, buf, max_len)) {
  1150. rc = -EFAULT;
  1151. goto error;
  1152. }
  1153. *ppos += len;
  1154. error:
  1155. mutex_unlock(&display->display_lock);
  1156. kfree(buf);
  1157. return len;
  1158. }
  1159. static ssize_t debugfs_esd_trigger_check(struct file *file,
  1160. const char __user *user_buf,
  1161. size_t user_len,
  1162. loff_t *ppos)
  1163. {
  1164. struct dsi_display *display = file->private_data;
  1165. char *buf;
  1166. int rc = 0;
  1167. struct drm_panel_esd_config *esd_config = &display->panel->esd_config;
  1168. u32 esd_trigger;
  1169. size_t len;
  1170. if (!display)
  1171. return -ENODEV;
  1172. if (*ppos)
  1173. return 0;
  1174. if (user_len > sizeof(u32))
  1175. return -EINVAL;
  1176. if (!user_len || !user_buf)
  1177. return -EINVAL;
  1178. if (!display->panel ||
  1179. atomic_read(&display->panel->esd_recovery_pending))
  1180. return user_len;
  1181. if (!esd_config->esd_enabled) {
  1182. DSI_ERR("ESD feature is not enabled\n");
  1183. return -EINVAL;
  1184. }
  1185. buf = kzalloc(ESD_TRIGGER_STRING_MAX_LEN, GFP_KERNEL);
  1186. if (!buf)
  1187. return -ENOMEM;
  1188. len = min_t(size_t, user_len, ESD_TRIGGER_STRING_MAX_LEN - 1);
  1189. if (copy_from_user(buf, user_buf, len)) {
  1190. rc = -EINVAL;
  1191. goto error;
  1192. }
  1193. buf[len] = '\0'; /* terminate the string */
  1194. if (kstrtouint(buf, 10, &esd_trigger)) {
  1195. rc = -EINVAL;
  1196. goto error;
  1197. }
  1198. if (esd_trigger != 1) {
  1199. rc = -EINVAL;
  1200. goto error;
  1201. }
  1202. display->esd_trigger = esd_trigger;
  1203. if (display->esd_trigger) {
  1204. DSI_INFO("ESD attack triggered by user\n");
  1205. rc = dsi_panel_trigger_esd_attack(display->panel);
  1206. if (rc) {
  1207. DSI_ERR("Failed to trigger ESD attack\n");
  1208. goto error;
  1209. }
  1210. }
  1211. rc = len;
  1212. error:
  1213. kfree(buf);
  1214. return rc;
  1215. }
  1216. static ssize_t debugfs_alter_esd_check_mode(struct file *file,
  1217. const char __user *user_buf,
  1218. size_t user_len,
  1219. loff_t *ppos)
  1220. {
  1221. struct dsi_display *display = file->private_data;
  1222. struct drm_panel_esd_config *esd_config;
  1223. char *buf;
  1224. int rc = 0;
  1225. size_t len;
  1226. if (!display)
  1227. return -ENODEV;
  1228. if (*ppos)
  1229. return 0;
  1230. buf = kzalloc(ESD_MODE_STRING_MAX_LEN, GFP_KERNEL);
  1231. if (ZERO_OR_NULL_PTR(buf))
  1232. return -ENOMEM;
  1233. len = min_t(size_t, user_len, ESD_MODE_STRING_MAX_LEN - 1);
  1234. if (copy_from_user(buf, user_buf, len)) {
  1235. rc = -EINVAL;
  1236. goto error;
  1237. }
  1238. buf[len] = '\0'; /* terminate the string */
  1239. if (!display->panel) {
  1240. rc = -EINVAL;
  1241. goto error;
  1242. }
  1243. esd_config = &display->panel->esd_config;
  1244. if (!esd_config) {
  1245. DSI_ERR("Invalid panel esd config\n");
  1246. rc = -EINVAL;
  1247. goto error;
  1248. }
  1249. if (!esd_config->esd_enabled) {
  1250. rc = -EINVAL;
  1251. goto error;
  1252. }
  1253. if (!strcmp(buf, "te_signal_check\n")) {
  1254. if (display->panel->panel_mode == DSI_OP_VIDEO_MODE) {
  1255. DSI_INFO("TE based ESD check for Video Mode panels is not allowed\n");
  1256. rc = -EINVAL;
  1257. goto error;
  1258. }
  1259. DSI_INFO("ESD check is switched to TE mode by user\n");
  1260. esd_config->status_mode = ESD_MODE_PANEL_TE;
  1261. dsi_display_change_te_irq_status(display, true);
  1262. }
  1263. if (!strcmp(buf, "reg_read\n")) {
  1264. DSI_INFO("ESD check is switched to reg read by user\n");
  1265. rc = dsi_panel_parse_esd_reg_read_configs(display->panel);
  1266. if (rc) {
  1267. DSI_ERR("failed to alter esd check mode,rc=%d\n",
  1268. rc);
  1269. rc = user_len;
  1270. goto error;
  1271. }
  1272. esd_config->status_mode = ESD_MODE_REG_READ;
  1273. if (dsi_display_is_te_based_esd(display))
  1274. dsi_display_change_te_irq_status(display, false);
  1275. }
  1276. if (!strcmp(buf, "esd_sw_sim_success\n"))
  1277. esd_config->status_mode = ESD_MODE_SW_SIM_SUCCESS;
  1278. if (!strcmp(buf, "esd_sw_sim_failure\n"))
  1279. esd_config->status_mode = ESD_MODE_SW_SIM_FAILURE;
  1280. rc = len;
  1281. error:
  1282. kfree(buf);
  1283. return rc;
  1284. }
  1285. static ssize_t debugfs_read_esd_check_mode(struct file *file,
  1286. char __user *user_buf,
  1287. size_t user_len,
  1288. loff_t *ppos)
  1289. {
  1290. struct dsi_display *display = file->private_data;
  1291. struct drm_panel_esd_config *esd_config;
  1292. char *buf;
  1293. int rc = 0;
  1294. size_t len = 0;
  1295. if (!display)
  1296. return -ENODEV;
  1297. if (*ppos)
  1298. return 0;
  1299. if (!display->panel) {
  1300. DSI_ERR("invalid panel data\n");
  1301. return -EINVAL;
  1302. }
  1303. buf = kzalloc(ESD_MODE_STRING_MAX_LEN, GFP_KERNEL);
  1304. if (ZERO_OR_NULL_PTR(buf))
  1305. return -ENOMEM;
  1306. esd_config = &display->panel->esd_config;
  1307. if (!esd_config) {
  1308. DSI_ERR("Invalid panel esd config\n");
  1309. rc = -EINVAL;
  1310. goto error;
  1311. }
  1312. len = min_t(size_t, user_len, ESD_MODE_STRING_MAX_LEN - 1);
  1313. if (!esd_config->esd_enabled) {
  1314. rc = snprintf(buf, len, "ESD feature not enabled");
  1315. goto output_mode;
  1316. }
  1317. switch (esd_config->status_mode) {
  1318. case ESD_MODE_REG_READ:
  1319. rc = snprintf(buf, len, "reg_read");
  1320. break;
  1321. case ESD_MODE_PANEL_TE:
  1322. rc = snprintf(buf, len, "te_signal_check");
  1323. break;
  1324. case ESD_MODE_SW_SIM_FAILURE:
  1325. rc = snprintf(buf, len, "esd_sw_sim_failure");
  1326. break;
  1327. case ESD_MODE_SW_SIM_SUCCESS:
  1328. rc = snprintf(buf, len, "esd_sw_sim_success");
  1329. break;
  1330. default:
  1331. rc = snprintf(buf, len, "invalid");
  1332. break;
  1333. }
  1334. output_mode:
  1335. if (!rc) {
  1336. rc = -EINVAL;
  1337. goto error;
  1338. }
  1339. if (copy_to_user(user_buf, buf, len)) {
  1340. rc = -EFAULT;
  1341. goto error;
  1342. }
  1343. *ppos += len;
  1344. error:
  1345. kfree(buf);
  1346. return len;
  1347. }
  1348. static ssize_t debugfs_update_cmd_scheduling_params(struct file *file,
  1349. const char __user *user_buf,
  1350. size_t user_len,
  1351. loff_t *ppos)
  1352. {
  1353. struct dsi_display *display = file->private_data;
  1354. struct dsi_display_ctrl *display_ctrl;
  1355. char *buf;
  1356. int rc = 0;
  1357. u32 line = 0, window = 0;
  1358. size_t len;
  1359. int i;
  1360. if (!display)
  1361. return -ENODEV;
  1362. if (*ppos)
  1363. return 0;
  1364. buf = kzalloc(256, GFP_KERNEL);
  1365. if (ZERO_OR_NULL_PTR(buf))
  1366. return -ENOMEM;
  1367. len = min_t(size_t, user_len, 255);
  1368. if (copy_from_user(buf, user_buf, len)) {
  1369. rc = -EINVAL;
  1370. goto error;
  1371. }
  1372. buf[len] = '\0'; /* terminate the string */
  1373. if (sscanf(buf, "%d %d", &line, &window) != 2)
  1374. return -EFAULT;
  1375. display_for_each_ctrl(i, display) {
  1376. struct dsi_ctrl *ctrl;
  1377. display_ctrl = &display->ctrl[i];
  1378. if (!display_ctrl->ctrl)
  1379. continue;
  1380. ctrl = display_ctrl->ctrl;
  1381. ctrl->host_config.common_config.dma_sched_line = line;
  1382. ctrl->host_config.common_config.dma_sched_window = window;
  1383. }
  1384. rc = len;
  1385. error:
  1386. kfree(buf);
  1387. return rc;
  1388. }
  1389. static ssize_t debugfs_read_cmd_scheduling_params(struct file *file,
  1390. char __user *user_buf,
  1391. size_t user_len,
  1392. loff_t *ppos)
  1393. {
  1394. struct dsi_display *display = file->private_data;
  1395. struct dsi_display_ctrl *m_ctrl;
  1396. struct dsi_ctrl *ctrl;
  1397. char *buf;
  1398. u32 len = 0;
  1399. int rc = 0;
  1400. size_t max_len = min_t(size_t, user_len, SZ_4K);
  1401. if (!display)
  1402. return -ENODEV;
  1403. if (*ppos)
  1404. return 0;
  1405. m_ctrl = &display->ctrl[display->cmd_master_idx];
  1406. ctrl = m_ctrl->ctrl;
  1407. buf = kzalloc(max_len, GFP_KERNEL);
  1408. if (ZERO_OR_NULL_PTR(buf))
  1409. return -ENOMEM;
  1410. len += scnprintf(buf, max_len, "Schedule command window start: %d\n",
  1411. ctrl->host_config.common_config.dma_sched_line);
  1412. len += scnprintf((buf + len), max_len - len,
  1413. "Schedule command window width: %d\n",
  1414. ctrl->host_config.common_config.dma_sched_window);
  1415. if (len > max_len)
  1416. len = max_len;
  1417. if (copy_to_user(user_buf, buf, len)) {
  1418. rc = -EFAULT;
  1419. goto error;
  1420. }
  1421. *ppos += len;
  1422. error:
  1423. kfree(buf);
  1424. return len;
  1425. }
  1426. static const struct file_operations dump_info_fops = {
  1427. .open = simple_open,
  1428. .read = debugfs_dump_info_read,
  1429. };
  1430. static const struct file_operations misr_data_fops = {
  1431. .open = simple_open,
  1432. .read = debugfs_misr_read,
  1433. .write = debugfs_misr_setup,
  1434. };
  1435. static const struct file_operations esd_trigger_fops = {
  1436. .open = simple_open,
  1437. .write = debugfs_esd_trigger_check,
  1438. };
  1439. static const struct file_operations esd_check_mode_fops = {
  1440. .open = simple_open,
  1441. .write = debugfs_alter_esd_check_mode,
  1442. .read = debugfs_read_esd_check_mode,
  1443. };
  1444. static const struct file_operations dsi_command_scheduling_fops = {
  1445. .open = simple_open,
  1446. .write = debugfs_update_cmd_scheduling_params,
  1447. .read = debugfs_read_cmd_scheduling_params,
  1448. };
  1449. static int dsi_display_debugfs_init(struct dsi_display *display)
  1450. {
  1451. int rc = 0;
  1452. struct dentry *dir, *dump_file, *misr_data;
  1453. char name[MAX_NAME_SIZE];
  1454. int i;
  1455. dir = debugfs_create_dir(display->name, NULL);
  1456. if (IS_ERR_OR_NULL(dir)) {
  1457. rc = PTR_ERR(dir);
  1458. DSI_ERR("[%s] debugfs create dir failed, rc = %d\n",
  1459. display->name, rc);
  1460. goto error;
  1461. }
  1462. dump_file = debugfs_create_file("dump_info",
  1463. 0400,
  1464. dir,
  1465. display,
  1466. &dump_info_fops);
  1467. if (IS_ERR_OR_NULL(dump_file)) {
  1468. rc = PTR_ERR(dump_file);
  1469. DSI_ERR("[%s] debugfs create dump info file failed, rc=%d\n",
  1470. display->name, rc);
  1471. goto error_remove_dir;
  1472. }
  1473. dump_file = debugfs_create_file("esd_trigger",
  1474. 0644,
  1475. dir,
  1476. display,
  1477. &esd_trigger_fops);
  1478. if (IS_ERR_OR_NULL(dump_file)) {
  1479. rc = PTR_ERR(dump_file);
  1480. DSI_ERR("[%s] debugfs for esd trigger file failed, rc=%d\n",
  1481. display->name, rc);
  1482. goto error_remove_dir;
  1483. }
  1484. dump_file = debugfs_create_file("esd_check_mode",
  1485. 0644,
  1486. dir,
  1487. display,
  1488. &esd_check_mode_fops);
  1489. if (IS_ERR_OR_NULL(dump_file)) {
  1490. rc = PTR_ERR(dump_file);
  1491. DSI_ERR("[%s] debugfs for esd check mode failed, rc=%d\n",
  1492. display->name, rc);
  1493. goto error_remove_dir;
  1494. }
  1495. dump_file = debugfs_create_file("cmd_sched_params",
  1496. 0644,
  1497. dir,
  1498. display,
  1499. &dsi_command_scheduling_fops);
  1500. if (IS_ERR_OR_NULL(dump_file)) {
  1501. rc = PTR_ERR(dump_file);
  1502. DSI_ERR("[%s] debugfs for cmd scheduling file failed, rc=%d\n",
  1503. display->name, rc);
  1504. goto error_remove_dir;
  1505. }
  1506. misr_data = debugfs_create_file("misr_data",
  1507. 0600,
  1508. dir,
  1509. display,
  1510. &misr_data_fops);
  1511. if (IS_ERR_OR_NULL(misr_data)) {
  1512. rc = PTR_ERR(misr_data);
  1513. DSI_ERR("[%s] debugfs create misr datafile failed, rc=%d\n",
  1514. display->name, rc);
  1515. goto error_remove_dir;
  1516. }
  1517. display_for_each_ctrl(i, display) {
  1518. struct msm_dsi_phy *phy = display->ctrl[i].phy;
  1519. if (!phy || !phy->name)
  1520. continue;
  1521. snprintf(name, ARRAY_SIZE(name),
  1522. "%s_allow_phy_power_off", phy->name);
  1523. dump_file = debugfs_create_bool(name, 0600, dir,
  1524. &phy->allow_phy_power_off);
  1525. if (IS_ERR_OR_NULL(dump_file)) {
  1526. rc = PTR_ERR(dump_file);
  1527. DSI_ERR("[%s] debugfs create %s failed, rc=%d\n",
  1528. display->name, name, rc);
  1529. goto error_remove_dir;
  1530. }
  1531. snprintf(name, ARRAY_SIZE(name),
  1532. "%s_regulator_min_datarate_bps", phy->name);
  1533. dump_file = debugfs_create_u32(name, 0600, dir,
  1534. &phy->regulator_min_datarate_bps);
  1535. if (IS_ERR_OR_NULL(dump_file)) {
  1536. rc = PTR_ERR(dump_file);
  1537. DSI_ERR("[%s] debugfs create %s failed, rc=%d\n",
  1538. display->name, name, rc);
  1539. goto error_remove_dir;
  1540. }
  1541. }
  1542. if (!debugfs_create_bool("ulps_feature_enable", 0600, dir,
  1543. &display->panel->ulps_feature_enabled)) {
  1544. DSI_ERR("[%s] debugfs create ulps feature enable file failed\n",
  1545. display->name);
  1546. goto error_remove_dir;
  1547. }
  1548. if (!debugfs_create_bool("ulps_suspend_feature_enable", 0600, dir,
  1549. &display->panel->ulps_suspend_enabled)) {
  1550. DSI_ERR("[%s] debugfs create ulps-suspend feature enable file failed\n",
  1551. display->name);
  1552. goto error_remove_dir;
  1553. }
  1554. if (!debugfs_create_bool("ulps_status", 0400, dir,
  1555. &display->ulps_enabled)) {
  1556. DSI_ERR("[%s] debugfs create ulps status file failed\n",
  1557. display->name);
  1558. goto error_remove_dir;
  1559. }
  1560. if (!debugfs_create_u32("clk_gating_config", 0600, dir,
  1561. &display->clk_gating_config)) {
  1562. DSI_ERR("[%s] debugfs create clk gating config failed\n",
  1563. display->name);
  1564. goto error_remove_dir;
  1565. }
  1566. display->root = dir;
  1567. dsi_parser_dbg_init(display->parser, dir);
  1568. return rc;
  1569. error_remove_dir:
  1570. debugfs_remove(dir);
  1571. error:
  1572. return rc;
  1573. }
  1574. static int dsi_display_debugfs_deinit(struct dsi_display *display)
  1575. {
  1576. debugfs_remove_recursive(display->root);
  1577. return 0;
  1578. }
  1579. #else
  1580. static int dsi_display_debugfs_init(struct dsi_display *display)
  1581. {
  1582. return 0;
  1583. }
  1584. static int dsi_display_debugfs_deinit(struct dsi_display *display)
  1585. {
  1586. return 0;
  1587. }
  1588. #endif /* CONFIG_DEBUG_FS */
  1589. static void adjust_timing_by_ctrl_count(const struct dsi_display *display,
  1590. struct dsi_display_mode *mode)
  1591. {
  1592. struct dsi_host_common_cfg *host = &display->panel->host_config;
  1593. bool is_split_link = host->split_link.split_link_enabled;
  1594. u32 sublinks_count = host->split_link.num_sublinks;
  1595. if (is_split_link && sublinks_count > 1) {
  1596. mode->timing.h_active /= sublinks_count;
  1597. mode->timing.h_front_porch /= sublinks_count;
  1598. mode->timing.h_sync_width /= sublinks_count;
  1599. mode->timing.h_back_porch /= sublinks_count;
  1600. mode->timing.h_skew /= sublinks_count;
  1601. mode->pixel_clk_khz /= sublinks_count;
  1602. } else {
  1603. if (mode->priv_info->dsc_enabled)
  1604. mode->priv_info->dsc.config.pic_width =
  1605. mode->timing.h_active;
  1606. mode->timing.h_active /= display->ctrl_count;
  1607. mode->timing.h_front_porch /= display->ctrl_count;
  1608. mode->timing.h_sync_width /= display->ctrl_count;
  1609. mode->timing.h_back_porch /= display->ctrl_count;
  1610. mode->timing.h_skew /= display->ctrl_count;
  1611. mode->pixel_clk_khz /= display->ctrl_count;
  1612. }
  1613. }
  1614. static int dsi_display_is_ulps_req_valid(struct dsi_display *display,
  1615. bool enable)
  1616. {
  1617. /* TODO: make checks based on cont. splash */
  1618. DSI_DEBUG("checking ulps req validity\n");
  1619. if (atomic_read(&display->panel->esd_recovery_pending)) {
  1620. DSI_DEBUG("%s: ESD recovery sequence underway\n", __func__);
  1621. return false;
  1622. }
  1623. if (!dsi_panel_ulps_feature_enabled(display->panel) &&
  1624. !display->panel->ulps_suspend_enabled) {
  1625. DSI_DEBUG("%s: ULPS feature is not enabled\n", __func__);
  1626. return false;
  1627. }
  1628. if (!dsi_panel_initialized(display->panel) &&
  1629. !display->panel->ulps_suspend_enabled) {
  1630. DSI_DEBUG("%s: panel not yet initialized\n", __func__);
  1631. return false;
  1632. }
  1633. if (enable && display->ulps_enabled) {
  1634. DSI_DEBUG("ULPS already enabled\n");
  1635. return false;
  1636. } else if (!enable && !display->ulps_enabled) {
  1637. DSI_DEBUG("ULPS already disabled\n");
  1638. return false;
  1639. }
  1640. /*
  1641. * No need to enter ULPS when transitioning from splash screen to
  1642. * boot animation or trusted vm environments since it is expected
  1643. * that the clocks would be turned right back on.
  1644. */
  1645. if (enable && is_skip_op_required(display))
  1646. return false;
  1647. return true;
  1648. }
  1649. /**
  1650. * dsi_display_set_ulps() - set ULPS state for DSI lanes.
  1651. * @dsi_display: DSI display handle.
  1652. * @enable: enable/disable ULPS.
  1653. *
  1654. * ULPS can be enabled/disabled after DSI host engine is turned on.
  1655. *
  1656. * Return: error code.
  1657. */
  1658. static int dsi_display_set_ulps(struct dsi_display *display, bool enable)
  1659. {
  1660. int rc = 0;
  1661. int i = 0;
  1662. struct dsi_display_ctrl *m_ctrl, *ctrl;
  1663. if (!display) {
  1664. DSI_ERR("Invalid params\n");
  1665. return -EINVAL;
  1666. }
  1667. if (!dsi_display_is_ulps_req_valid(display, enable)) {
  1668. DSI_DEBUG("%s: skipping ULPS config, enable=%d\n",
  1669. __func__, enable);
  1670. return 0;
  1671. }
  1672. m_ctrl = &display->ctrl[display->cmd_master_idx];
  1673. /*
  1674. * ULPS entry-exit can be either through the DSI controller or
  1675. * the DSI PHY depending on hardware variation. For some chipsets,
  1676. * both controller version and phy version ulps entry-exit ops can
  1677. * be present. To handle such cases, send ulps request through PHY,
  1678. * if ulps request is handled in PHY, then no need to send request
  1679. * through controller.
  1680. */
  1681. rc = dsi_phy_set_ulps(m_ctrl->phy, &display->config, enable,
  1682. display->clamp_enabled);
  1683. if (rc == DSI_PHY_ULPS_ERROR) {
  1684. DSI_ERR("Ulps PHY state change(%d) failed\n", enable);
  1685. return -EINVAL;
  1686. }
  1687. else if (rc == DSI_PHY_ULPS_HANDLED) {
  1688. display_for_each_ctrl(i, display) {
  1689. ctrl = &display->ctrl[i];
  1690. if (!ctrl->ctrl || (ctrl == m_ctrl))
  1691. continue;
  1692. rc = dsi_phy_set_ulps(ctrl->phy, &display->config,
  1693. enable, display->clamp_enabled);
  1694. if (rc == DSI_PHY_ULPS_ERROR) {
  1695. DSI_ERR("Ulps PHY state change(%d) failed\n",
  1696. enable);
  1697. return -EINVAL;
  1698. }
  1699. }
  1700. }
  1701. else if (rc == DSI_PHY_ULPS_NOT_HANDLED) {
  1702. rc = dsi_ctrl_set_ulps(m_ctrl->ctrl, enable);
  1703. if (rc) {
  1704. DSI_ERR("Ulps controller state change(%d) failed\n",
  1705. enable);
  1706. return rc;
  1707. }
  1708. display_for_each_ctrl(i, display) {
  1709. ctrl = &display->ctrl[i];
  1710. if (!ctrl->ctrl || (ctrl == m_ctrl))
  1711. continue;
  1712. rc = dsi_ctrl_set_ulps(ctrl->ctrl, enable);
  1713. if (rc) {
  1714. DSI_ERR("Ulps controller state change(%d) failed\n",
  1715. enable);
  1716. return rc;
  1717. }
  1718. }
  1719. }
  1720. display->ulps_enabled = enable;
  1721. return 0;
  1722. }
  1723. /**
  1724. * dsi_display_set_clamp() - set clamp state for DSI IO.
  1725. * @dsi_display: DSI display handle.
  1726. * @enable: enable/disable clamping.
  1727. *
  1728. * Return: error code.
  1729. */
  1730. static int dsi_display_set_clamp(struct dsi_display *display, bool enable)
  1731. {
  1732. int rc = 0;
  1733. int i = 0;
  1734. struct dsi_display_ctrl *m_ctrl, *ctrl;
  1735. bool ulps_enabled = false;
  1736. if (!display) {
  1737. DSI_ERR("Invalid params\n");
  1738. return -EINVAL;
  1739. }
  1740. m_ctrl = &display->ctrl[display->cmd_master_idx];
  1741. ulps_enabled = display->ulps_enabled;
  1742. /*
  1743. * Clamp control can be either through the DSI controller or
  1744. * the DSI PHY depending on hardware variation
  1745. */
  1746. rc = dsi_ctrl_set_clamp_state(m_ctrl->ctrl, enable, ulps_enabled);
  1747. if (rc) {
  1748. DSI_ERR("DSI ctrl clamp state change(%d) failed\n", enable);
  1749. return rc;
  1750. }
  1751. rc = dsi_phy_set_clamp_state(m_ctrl->phy, enable);
  1752. if (rc) {
  1753. DSI_ERR("DSI phy clamp state change(%d) failed\n", enable);
  1754. return rc;
  1755. }
  1756. display_for_each_ctrl(i, display) {
  1757. ctrl = &display->ctrl[i];
  1758. if (!ctrl->ctrl || (ctrl == m_ctrl))
  1759. continue;
  1760. rc = dsi_ctrl_set_clamp_state(ctrl->ctrl, enable, ulps_enabled);
  1761. if (rc) {
  1762. DSI_ERR("DSI Clamp state change(%d) failed\n", enable);
  1763. return rc;
  1764. }
  1765. rc = dsi_phy_set_clamp_state(ctrl->phy, enable);
  1766. if (rc) {
  1767. DSI_ERR("DSI phy clamp state change(%d) failed\n",
  1768. enable);
  1769. return rc;
  1770. }
  1771. DSI_DEBUG("Clamps %s for ctrl%d\n",
  1772. enable ? "enabled" : "disabled", i);
  1773. }
  1774. display->clamp_enabled = enable;
  1775. return 0;
  1776. }
  1777. /**
  1778. * dsi_display_setup_ctrl() - setup DSI controller.
  1779. * @dsi_display: DSI display handle.
  1780. *
  1781. * Return: error code.
  1782. */
  1783. static int dsi_display_ctrl_setup(struct dsi_display *display)
  1784. {
  1785. int rc = 0;
  1786. int i = 0;
  1787. struct dsi_display_ctrl *ctrl, *m_ctrl;
  1788. if (!display) {
  1789. DSI_ERR("Invalid params\n");
  1790. return -EINVAL;
  1791. }
  1792. m_ctrl = &display->ctrl[display->cmd_master_idx];
  1793. rc = dsi_ctrl_setup(m_ctrl->ctrl);
  1794. if (rc) {
  1795. DSI_ERR("DSI controller setup failed\n");
  1796. return rc;
  1797. }
  1798. display_for_each_ctrl(i, display) {
  1799. ctrl = &display->ctrl[i];
  1800. if (!ctrl->ctrl || (ctrl == m_ctrl))
  1801. continue;
  1802. rc = dsi_ctrl_setup(ctrl->ctrl);
  1803. if (rc) {
  1804. DSI_ERR("DSI controller setup failed\n");
  1805. return rc;
  1806. }
  1807. }
  1808. return 0;
  1809. }
  1810. static int dsi_display_phy_enable(struct dsi_display *display);
  1811. /**
  1812. * dsi_display_phy_idle_on() - enable DSI PHY while coming out of idle screen.
  1813. * @dsi_display: DSI display handle.
  1814. * @mmss_clamp: True if clamp is enabled.
  1815. *
  1816. * Return: error code.
  1817. */
  1818. static int dsi_display_phy_idle_on(struct dsi_display *display,
  1819. bool mmss_clamp)
  1820. {
  1821. int rc = 0;
  1822. int i = 0;
  1823. struct dsi_display_ctrl *m_ctrl, *ctrl;
  1824. if (!display) {
  1825. DSI_ERR("Invalid params\n");
  1826. return -EINVAL;
  1827. }
  1828. if (mmss_clamp && !display->phy_idle_power_off) {
  1829. dsi_display_phy_enable(display);
  1830. return 0;
  1831. }
  1832. m_ctrl = &display->ctrl[display->cmd_master_idx];
  1833. rc = dsi_phy_idle_ctrl(m_ctrl->phy, true);
  1834. if (rc) {
  1835. DSI_ERR("DSI controller setup failed\n");
  1836. return rc;
  1837. }
  1838. display_for_each_ctrl(i, display) {
  1839. ctrl = &display->ctrl[i];
  1840. if (!ctrl->ctrl || (ctrl == m_ctrl))
  1841. continue;
  1842. rc = dsi_phy_idle_ctrl(ctrl->phy, true);
  1843. if (rc) {
  1844. DSI_ERR("DSI controller setup failed\n");
  1845. return rc;
  1846. }
  1847. }
  1848. display->phy_idle_power_off = false;
  1849. return 0;
  1850. }
  1851. /**
  1852. * dsi_display_phy_idle_off() - disable DSI PHY while going to idle screen.
  1853. * @dsi_display: DSI display handle.
  1854. *
  1855. * Return: error code.
  1856. */
  1857. static int dsi_display_phy_idle_off(struct dsi_display *display)
  1858. {
  1859. int rc = 0;
  1860. int i = 0;
  1861. struct dsi_display_ctrl *m_ctrl, *ctrl;
  1862. if (!display) {
  1863. DSI_ERR("Invalid params\n");
  1864. return -EINVAL;
  1865. }
  1866. display_for_each_ctrl(i, display) {
  1867. struct msm_dsi_phy *phy = display->ctrl[i].phy;
  1868. if (!phy)
  1869. continue;
  1870. if (!phy->allow_phy_power_off) {
  1871. DSI_DEBUG("phy doesn't support this feature\n");
  1872. return 0;
  1873. }
  1874. }
  1875. m_ctrl = &display->ctrl[display->cmd_master_idx];
  1876. rc = dsi_phy_idle_ctrl(m_ctrl->phy, false);
  1877. if (rc) {
  1878. DSI_ERR("[%s] failed to enable cmd engine, rc=%d\n",
  1879. display->name, rc);
  1880. return rc;
  1881. }
  1882. display_for_each_ctrl(i, display) {
  1883. ctrl = &display->ctrl[i];
  1884. if (!ctrl->ctrl || (ctrl == m_ctrl))
  1885. continue;
  1886. rc = dsi_phy_idle_ctrl(ctrl->phy, false);
  1887. if (rc) {
  1888. DSI_ERR("DSI controller setup failed\n");
  1889. return rc;
  1890. }
  1891. }
  1892. display->phy_idle_power_off = true;
  1893. return 0;
  1894. }
  1895. void dsi_display_enable_event(struct drm_connector *connector,
  1896. struct dsi_display *display,
  1897. uint32_t event_idx, struct dsi_event_cb_info *event_info,
  1898. bool enable)
  1899. {
  1900. uint32_t irq_status_idx = DSI_STATUS_INTERRUPT_COUNT;
  1901. int i;
  1902. if (!display) {
  1903. DSI_ERR("invalid display\n");
  1904. return;
  1905. }
  1906. if (event_info)
  1907. event_info->event_idx = event_idx;
  1908. switch (event_idx) {
  1909. case SDE_CONN_EVENT_VID_DONE:
  1910. irq_status_idx = DSI_SINT_VIDEO_MODE_FRAME_DONE;
  1911. break;
  1912. case SDE_CONN_EVENT_CMD_DONE:
  1913. irq_status_idx = DSI_SINT_CMD_FRAME_DONE;
  1914. break;
  1915. case SDE_CONN_EVENT_VID_FIFO_OVERFLOW:
  1916. case SDE_CONN_EVENT_CMD_FIFO_UNDERFLOW:
  1917. if (event_info) {
  1918. display_for_each_ctrl(i, display)
  1919. display->ctrl[i].ctrl->recovery_cb =
  1920. *event_info;
  1921. }
  1922. break;
  1923. case SDE_CONN_EVENT_PANEL_ID:
  1924. if (event_info)
  1925. display_for_each_ctrl(i, display)
  1926. display->ctrl[i].ctrl->panel_id_cb
  1927. = *event_info;
  1928. break;
  1929. default:
  1930. /* nothing to do */
  1931. DSI_DEBUG("[%s] unhandled event %d\n", display->name, event_idx);
  1932. return;
  1933. }
  1934. if (enable) {
  1935. display_for_each_ctrl(i, display)
  1936. dsi_ctrl_enable_status_interrupt(
  1937. display->ctrl[i].ctrl, irq_status_idx,
  1938. event_info);
  1939. } else {
  1940. display_for_each_ctrl(i, display)
  1941. dsi_ctrl_disable_status_interrupt(
  1942. display->ctrl[i].ctrl, irq_status_idx);
  1943. }
  1944. }
  1945. static int dsi_display_ctrl_power_on(struct dsi_display *display)
  1946. {
  1947. int rc = 0;
  1948. int i;
  1949. struct dsi_display_ctrl *ctrl;
  1950. /* Sequence does not matter for split dsi usecases */
  1951. display_for_each_ctrl(i, display) {
  1952. ctrl = &display->ctrl[i];
  1953. if (!ctrl->ctrl)
  1954. continue;
  1955. rc = dsi_ctrl_set_power_state(ctrl->ctrl,
  1956. DSI_CTRL_POWER_VREG_ON);
  1957. if (rc) {
  1958. DSI_ERR("[%s] Failed to set power state, rc=%d\n",
  1959. ctrl->ctrl->name, rc);
  1960. goto error;
  1961. }
  1962. }
  1963. return rc;
  1964. error:
  1965. for (i = i - 1; i >= 0; i--) {
  1966. ctrl = &display->ctrl[i];
  1967. if (!ctrl->ctrl)
  1968. continue;
  1969. (void)dsi_ctrl_set_power_state(ctrl->ctrl,
  1970. DSI_CTRL_POWER_VREG_OFF);
  1971. }
  1972. return rc;
  1973. }
  1974. static int dsi_display_ctrl_power_off(struct dsi_display *display)
  1975. {
  1976. int rc = 0;
  1977. int i;
  1978. struct dsi_display_ctrl *ctrl;
  1979. /* Sequence does not matter for split dsi usecases */
  1980. display_for_each_ctrl(i, display) {
  1981. ctrl = &display->ctrl[i];
  1982. if (!ctrl->ctrl)
  1983. continue;
  1984. rc = dsi_ctrl_set_power_state(ctrl->ctrl,
  1985. DSI_CTRL_POWER_VREG_OFF);
  1986. if (rc) {
  1987. DSI_ERR("[%s] Failed to power off, rc=%d\n",
  1988. ctrl->ctrl->name, rc);
  1989. goto error;
  1990. }
  1991. }
  1992. error:
  1993. return rc;
  1994. }
  1995. static void dsi_display_parse_cmdline_topology(struct dsi_display *display,
  1996. unsigned int display_type)
  1997. {
  1998. char *boot_str = NULL;
  1999. char *str = NULL;
  2000. char *sw_te = NULL;
  2001. unsigned long cmdline_topology = NO_OVERRIDE;
  2002. unsigned long cmdline_timing = NO_OVERRIDE;
  2003. unsigned long panel_id = NO_OVERRIDE;
  2004. if (display_type >= MAX_DSI_ACTIVE_DISPLAY) {
  2005. DSI_ERR("display_type=%d not supported\n", display_type);
  2006. goto end;
  2007. }
  2008. if (display_type == DSI_PRIMARY)
  2009. boot_str = dsi_display_primary;
  2010. else
  2011. boot_str = dsi_display_secondary;
  2012. sw_te = strnstr(boot_str, ":sim-swte", strlen(boot_str));
  2013. if (sw_te)
  2014. display->sw_te_using_wd = true;
  2015. str = strnstr(boot_str, ":panelid", strlen(boot_str));
  2016. if (str) {
  2017. if (kstrtol(str + strlen(":panelid"), INT_BASE_10,
  2018. (unsigned long *)&panel_id)) {
  2019. DSI_INFO("panel id not found: %s\n", boot_str);
  2020. } else {
  2021. DSI_INFO("panel id found: %lx\n", panel_id);
  2022. display->panel_id = panel_id;
  2023. }
  2024. }
  2025. str = strnstr(boot_str, ":config", strlen(boot_str));
  2026. if (str) {
  2027. if (sscanf(str, ":config%lu", &cmdline_topology) != 1) {
  2028. DSI_ERR("invalid config index override: %s\n",
  2029. boot_str);
  2030. goto end;
  2031. }
  2032. }
  2033. str = strnstr(boot_str, ":timing", strlen(boot_str));
  2034. if (str) {
  2035. if (sscanf(str, ":timing%lu", &cmdline_timing) != 1) {
  2036. DSI_ERR("invalid timing index override: %s\n",
  2037. boot_str);
  2038. cmdline_topology = NO_OVERRIDE;
  2039. goto end;
  2040. }
  2041. }
  2042. DSI_DEBUG("successfully parsed command line topology and timing\n");
  2043. end:
  2044. display->cmdline_topology = cmdline_topology;
  2045. display->cmdline_timing = cmdline_timing;
  2046. }
  2047. /**
  2048. * dsi_display_parse_boot_display_selection()- Parse DSI boot display name
  2049. *
  2050. * Return: returns error status
  2051. */
  2052. static int dsi_display_parse_boot_display_selection(void)
  2053. {
  2054. char *pos = NULL;
  2055. char disp_buf[MAX_CMDLINE_PARAM_LEN] = {'\0'};
  2056. int i, j;
  2057. for (i = 0; i < MAX_DSI_ACTIVE_DISPLAY; i++) {
  2058. strlcpy(disp_buf, boot_displays[i].boot_param,
  2059. MAX_CMDLINE_PARAM_LEN);
  2060. pos = strnstr(disp_buf, ":", MAX_CMDLINE_PARAM_LEN);
  2061. /* Use ':' as a delimiter to retrieve the display name */
  2062. if (!pos) {
  2063. DSI_DEBUG("display name[%s]is not valid\n", disp_buf);
  2064. continue;
  2065. }
  2066. for (j = 0; (disp_buf + j) < pos; j++)
  2067. boot_displays[i].name[j] = *(disp_buf + j);
  2068. boot_displays[i].name[j] = '\0';
  2069. boot_displays[i].boot_disp_en = true;
  2070. }
  2071. return 0;
  2072. }
  2073. static int dsi_display_phy_power_on(struct dsi_display *display)
  2074. {
  2075. int rc = 0;
  2076. int i;
  2077. struct dsi_display_ctrl *ctrl;
  2078. /* Sequence does not matter for split dsi usecases */
  2079. display_for_each_ctrl(i, display) {
  2080. ctrl = &display->ctrl[i];
  2081. if (!ctrl->ctrl)
  2082. continue;
  2083. rc = dsi_phy_set_power_state(ctrl->phy, true);
  2084. if (rc) {
  2085. DSI_ERR("[%s] Failed to set power state, rc=%d\n",
  2086. ctrl->phy->name, rc);
  2087. goto error;
  2088. }
  2089. }
  2090. return rc;
  2091. error:
  2092. for (i = i - 1; i >= 0; i--) {
  2093. ctrl = &display->ctrl[i];
  2094. if (!ctrl->phy)
  2095. continue;
  2096. (void)dsi_phy_set_power_state(ctrl->phy, false);
  2097. }
  2098. return rc;
  2099. }
  2100. static int dsi_display_phy_power_off(struct dsi_display *display)
  2101. {
  2102. int rc = 0;
  2103. int i;
  2104. struct dsi_display_ctrl *ctrl;
  2105. /* Sequence does not matter for split dsi usecases */
  2106. display_for_each_ctrl(i, display) {
  2107. ctrl = &display->ctrl[i];
  2108. if (!ctrl->phy)
  2109. continue;
  2110. rc = dsi_phy_set_power_state(ctrl->phy, false);
  2111. if (rc) {
  2112. DSI_ERR("[%s] Failed to power off, rc=%d\n",
  2113. ctrl->ctrl->name, rc);
  2114. goto error;
  2115. }
  2116. }
  2117. error:
  2118. return rc;
  2119. }
  2120. static int dsi_display_set_clk_src(struct dsi_display *display)
  2121. {
  2122. int rc = 0;
  2123. int i;
  2124. struct dsi_display_ctrl *m_ctrl, *ctrl;
  2125. /*
  2126. * For CPHY mode, the parent of mux_clks need to be set
  2127. * to Cphy_clks to have correct dividers for byte and
  2128. * pixel clocks.
  2129. */
  2130. if (display->panel->host_config.phy_type == DSI_PHY_TYPE_CPHY) {
  2131. rc = dsi_clk_update_parent(&display->clock_info.cphy_clks,
  2132. &display->clock_info.mux_clks);
  2133. if (rc) {
  2134. DSI_ERR("failed update mux parent to shadow\n");
  2135. return rc;
  2136. }
  2137. }
  2138. /*
  2139. * In case of split DSI usecases, the clock for master controller should
  2140. * be enabled before the other controller. Master controller in the
  2141. * clock context refers to the controller that sources the clock.
  2142. */
  2143. m_ctrl = &display->ctrl[display->clk_master_idx];
  2144. rc = dsi_ctrl_set_clock_source(m_ctrl->ctrl,
  2145. &display->clock_info.mux_clks);
  2146. if (rc) {
  2147. DSI_ERR("[%s] failed to set source clocks for master, rc=%d\n",
  2148. display->name, rc);
  2149. return rc;
  2150. }
  2151. /* Turn on rest of the controllers */
  2152. display_for_each_ctrl(i, display) {
  2153. ctrl = &display->ctrl[i];
  2154. if (!ctrl->ctrl || (ctrl == m_ctrl))
  2155. continue;
  2156. rc = dsi_ctrl_set_clock_source(ctrl->ctrl,
  2157. &display->clock_info.mux_clks);
  2158. if (rc) {
  2159. DSI_ERR("[%s] failed to set source clocks, rc=%d\n",
  2160. display->name, rc);
  2161. return rc;
  2162. }
  2163. }
  2164. return 0;
  2165. }
  2166. static int dsi_display_phy_reset_config(struct dsi_display *display,
  2167. bool enable)
  2168. {
  2169. int rc = 0;
  2170. int i;
  2171. struct dsi_display_ctrl *ctrl;
  2172. display_for_each_ctrl(i, display) {
  2173. ctrl = &display->ctrl[i];
  2174. rc = dsi_ctrl_phy_reset_config(ctrl->ctrl, enable);
  2175. if (rc) {
  2176. DSI_ERR("[%s] failed to %s phy reset, rc=%d\n",
  2177. display->name, enable ? "mask" : "unmask", rc);
  2178. return rc;
  2179. }
  2180. }
  2181. return 0;
  2182. }
  2183. static void dsi_display_toggle_resync_fifo(struct dsi_display *display)
  2184. {
  2185. struct dsi_display_ctrl *ctrl;
  2186. int i;
  2187. if (!display)
  2188. return;
  2189. display_for_each_ctrl(i, display) {
  2190. ctrl = &display->ctrl[i];
  2191. dsi_phy_toggle_resync_fifo(ctrl->phy);
  2192. }
  2193. /*
  2194. * After retime buffer synchronization we need to turn of clk_en_sel
  2195. * bit on each phy. Avoid this for Cphy.
  2196. */
  2197. if (display->panel->host_config.phy_type == DSI_PHY_TYPE_CPHY)
  2198. return;
  2199. display_for_each_ctrl(i, display) {
  2200. ctrl = &display->ctrl[i];
  2201. dsi_phy_reset_clk_en_sel(ctrl->phy);
  2202. }
  2203. }
  2204. static int dsi_display_ctrl_update(struct dsi_display *display)
  2205. {
  2206. int rc = 0;
  2207. int i;
  2208. struct dsi_display_ctrl *ctrl;
  2209. display_for_each_ctrl(i, display) {
  2210. ctrl = &display->ctrl[i];
  2211. rc = dsi_ctrl_host_timing_update(ctrl->ctrl);
  2212. if (rc) {
  2213. DSI_ERR("[%s] failed to update host_%d, rc=%d\n",
  2214. display->name, i, rc);
  2215. goto error_host_deinit;
  2216. }
  2217. }
  2218. return 0;
  2219. error_host_deinit:
  2220. for (i = i - 1; i >= 0; i--) {
  2221. ctrl = &display->ctrl[i];
  2222. (void)dsi_ctrl_host_deinit(ctrl->ctrl);
  2223. }
  2224. return rc;
  2225. }
  2226. static int dsi_display_ctrl_init(struct dsi_display *display)
  2227. {
  2228. int rc = 0;
  2229. int i;
  2230. struct dsi_display_ctrl *ctrl;
  2231. bool skip_op = is_skip_op_required(display);
  2232. /* when ULPS suspend feature is enabled, we will keep the lanes in
  2233. * ULPS during suspend state and clamp DSI phy. Hence while resuming
  2234. * we will programe DSI controller as part of core clock enable.
  2235. * After that we should not re-configure DSI controller again here for
  2236. * usecases where we are resuming from ulps suspend as it might put
  2237. * the HW in bad state.
  2238. */
  2239. if (!display->panel->ulps_suspend_enabled || !display->ulps_enabled) {
  2240. display_for_each_ctrl(i, display) {
  2241. ctrl = &display->ctrl[i];
  2242. rc = dsi_ctrl_host_init(ctrl->ctrl, skip_op);
  2243. if (rc) {
  2244. DSI_ERR(
  2245. "[%s] failed to init host_%d, skip_op=%d, rc=%d\n",
  2246. display->name, i, skip_op, rc);
  2247. goto error_host_deinit;
  2248. }
  2249. }
  2250. } else {
  2251. display_for_each_ctrl(i, display) {
  2252. ctrl = &display->ctrl[i];
  2253. rc = dsi_ctrl_update_host_state(ctrl->ctrl,
  2254. DSI_CTRL_OP_HOST_INIT,
  2255. true);
  2256. if (rc)
  2257. DSI_DEBUG("host init update failed rc=%d\n",
  2258. rc);
  2259. }
  2260. }
  2261. return rc;
  2262. error_host_deinit:
  2263. for (i = i - 1; i >= 0; i--) {
  2264. ctrl = &display->ctrl[i];
  2265. (void)dsi_ctrl_host_deinit(ctrl->ctrl);
  2266. }
  2267. return rc;
  2268. }
  2269. static int dsi_display_ctrl_deinit(struct dsi_display *display)
  2270. {
  2271. int rc = 0;
  2272. int i;
  2273. struct dsi_display_ctrl *ctrl;
  2274. display_for_each_ctrl(i, display) {
  2275. ctrl = &display->ctrl[i];
  2276. rc = dsi_ctrl_host_deinit(ctrl->ctrl);
  2277. if (rc) {
  2278. DSI_ERR("[%s] failed to deinit host_%d, rc=%d\n",
  2279. display->name, i, rc);
  2280. }
  2281. }
  2282. return rc;
  2283. }
  2284. static int dsi_display_ctrl_host_enable(struct dsi_display *display)
  2285. {
  2286. int rc = 0;
  2287. int i;
  2288. struct dsi_display_ctrl *m_ctrl, *ctrl;
  2289. bool skip_op = is_skip_op_required(display);
  2290. m_ctrl = &display->ctrl[display->cmd_master_idx];
  2291. rc = dsi_ctrl_set_host_engine_state(m_ctrl->ctrl,
  2292. DSI_CTRL_ENGINE_ON, skip_op);
  2293. if (rc) {
  2294. DSI_ERR("[%s]enable host engine failed, skip_op:%d rc:%d\n",
  2295. display->name, skip_op, rc);
  2296. goto error;
  2297. }
  2298. display_for_each_ctrl(i, display) {
  2299. ctrl = &display->ctrl[i];
  2300. if (!ctrl->ctrl || (ctrl == m_ctrl))
  2301. continue;
  2302. rc = dsi_ctrl_set_host_engine_state(ctrl->ctrl,
  2303. DSI_CTRL_ENGINE_ON, skip_op);
  2304. if (rc) {
  2305. DSI_ERR(
  2306. "[%s] enable host engine failed, skip_op:%d rc:%d\n",
  2307. display->name, skip_op, rc);
  2308. goto error_disable_master;
  2309. }
  2310. }
  2311. return rc;
  2312. error_disable_master:
  2313. (void)dsi_ctrl_set_host_engine_state(m_ctrl->ctrl,
  2314. DSI_CTRL_ENGINE_OFF, skip_op);
  2315. error:
  2316. return rc;
  2317. }
  2318. static int dsi_display_ctrl_host_disable(struct dsi_display *display)
  2319. {
  2320. int rc = 0;
  2321. int i;
  2322. struct dsi_display_ctrl *m_ctrl, *ctrl;
  2323. bool skip_op = is_skip_op_required(display);
  2324. m_ctrl = &display->ctrl[display->cmd_master_idx];
  2325. /*
  2326. * For platforms where ULPS is controlled by DSI controller block,
  2327. * do not disable dsi controller block if lanes are to be
  2328. * kept in ULPS during suspend. So just update the SW state
  2329. * and return early.
  2330. */
  2331. if (display->panel->ulps_suspend_enabled &&
  2332. !m_ctrl->phy->hw.ops.ulps_ops.ulps_request) {
  2333. display_for_each_ctrl(i, display) {
  2334. ctrl = &display->ctrl[i];
  2335. rc = dsi_ctrl_update_host_state(ctrl->ctrl,
  2336. DSI_CTRL_OP_HOST_ENGINE,
  2337. false);
  2338. if (rc)
  2339. DSI_DEBUG("host state update failed %d\n", rc);
  2340. }
  2341. return rc;
  2342. }
  2343. display_for_each_ctrl(i, display) {
  2344. ctrl = &display->ctrl[i];
  2345. if (!ctrl->ctrl || (ctrl == m_ctrl))
  2346. continue;
  2347. rc = dsi_ctrl_set_host_engine_state(ctrl->ctrl,
  2348. DSI_CTRL_ENGINE_OFF, skip_op);
  2349. if (rc)
  2350. DSI_ERR(
  2351. "[%s] disable host engine failed, skip_op:%d rc:%d\n",
  2352. display->name, skip_op, rc);
  2353. }
  2354. rc = dsi_ctrl_set_host_engine_state(m_ctrl->ctrl,
  2355. DSI_CTRL_ENGINE_OFF, skip_op);
  2356. if (rc) {
  2357. DSI_ERR("[%s] disable mhost engine failed, skip_op:%d rc:%d\n",
  2358. display->name, skip_op, rc);
  2359. goto error;
  2360. }
  2361. error:
  2362. return rc;
  2363. }
  2364. static int dsi_display_vid_engine_enable(struct dsi_display *display)
  2365. {
  2366. int rc = 0;
  2367. int i;
  2368. struct dsi_display_ctrl *m_ctrl, *ctrl;
  2369. bool skip_op = is_skip_op_required(display);
  2370. m_ctrl = &display->ctrl[display->video_master_idx];
  2371. rc = dsi_ctrl_set_vid_engine_state(m_ctrl->ctrl,
  2372. DSI_CTRL_ENGINE_ON, skip_op);
  2373. if (rc) {
  2374. DSI_ERR("[%s] enable mvid engine failed, skip_op:%d rc:%d\n",
  2375. display->name, skip_op, rc);
  2376. goto error;
  2377. }
  2378. display_for_each_ctrl(i, display) {
  2379. ctrl = &display->ctrl[i];
  2380. if (!ctrl->ctrl || (ctrl == m_ctrl))
  2381. continue;
  2382. rc = dsi_ctrl_set_vid_engine_state(ctrl->ctrl,
  2383. DSI_CTRL_ENGINE_ON, skip_op);
  2384. if (rc) {
  2385. DSI_ERR(
  2386. "[%s] enable vid engine failed, skip_op:%d rc:%d\n",
  2387. display->name, skip_op, rc);
  2388. goto error_disable_master;
  2389. }
  2390. }
  2391. return rc;
  2392. error_disable_master:
  2393. (void)dsi_ctrl_set_vid_engine_state(m_ctrl->ctrl,
  2394. DSI_CTRL_ENGINE_OFF, skip_op);
  2395. error:
  2396. return rc;
  2397. }
  2398. static int dsi_display_vid_engine_disable(struct dsi_display *display)
  2399. {
  2400. int rc = 0;
  2401. int i;
  2402. struct dsi_display_ctrl *m_ctrl, *ctrl;
  2403. bool skip_op = is_skip_op_required(display);
  2404. m_ctrl = &display->ctrl[display->video_master_idx];
  2405. display_for_each_ctrl(i, display) {
  2406. ctrl = &display->ctrl[i];
  2407. if (!ctrl->ctrl || (ctrl == m_ctrl))
  2408. continue;
  2409. rc = dsi_ctrl_set_vid_engine_state(ctrl->ctrl,
  2410. DSI_CTRL_ENGINE_OFF, skip_op);
  2411. if (rc)
  2412. DSI_ERR(
  2413. "[%s] disable vid engine failed, skip_op:%d rc:%d\n",
  2414. display->name, skip_op, rc);
  2415. }
  2416. rc = dsi_ctrl_set_vid_engine_state(m_ctrl->ctrl,
  2417. DSI_CTRL_ENGINE_OFF, skip_op);
  2418. if (rc)
  2419. DSI_ERR("[%s] disable mvid engine failed, skip_op:%d rc:%d\n",
  2420. display->name, skip_op, rc);
  2421. return rc;
  2422. }
  2423. static int dsi_display_phy_enable(struct dsi_display *display)
  2424. {
  2425. int rc = 0;
  2426. int i;
  2427. struct dsi_display_ctrl *m_ctrl, *ctrl;
  2428. enum dsi_phy_pll_source m_src = DSI_PLL_SOURCE_STANDALONE;
  2429. bool skip_op = is_skip_op_required(display);
  2430. m_ctrl = &display->ctrl[display->clk_master_idx];
  2431. if (display->ctrl_count > 1)
  2432. m_src = DSI_PLL_SOURCE_NATIVE;
  2433. rc = dsi_phy_enable(m_ctrl->phy, &display->config,
  2434. m_src, true, skip_op);
  2435. if (rc) {
  2436. DSI_ERR("[%s] failed to enable DSI PHY, skip_op=%d rc=%d\n",
  2437. display->name, skip_op, rc);
  2438. goto error;
  2439. }
  2440. display_for_each_ctrl(i, display) {
  2441. ctrl = &display->ctrl[i];
  2442. if (!ctrl->ctrl || (ctrl == m_ctrl))
  2443. continue;
  2444. rc = dsi_phy_enable(ctrl->phy, &display->config,
  2445. DSI_PLL_SOURCE_NON_NATIVE, true, skip_op);
  2446. if (rc) {
  2447. DSI_ERR(
  2448. "[%s] failed to enable DSI PHY, skip_op: %d rc=%d\n",
  2449. display->name, skip_op, rc);
  2450. goto error_disable_master;
  2451. }
  2452. }
  2453. return rc;
  2454. error_disable_master:
  2455. (void)dsi_phy_disable(m_ctrl->phy, skip_op);
  2456. error:
  2457. return rc;
  2458. }
  2459. static int dsi_display_phy_disable(struct dsi_display *display)
  2460. {
  2461. int rc = 0;
  2462. int i;
  2463. struct dsi_display_ctrl *m_ctrl, *ctrl;
  2464. bool skip_op = is_skip_op_required(display);
  2465. m_ctrl = &display->ctrl[display->clk_master_idx];
  2466. display_for_each_ctrl(i, display) {
  2467. ctrl = &display->ctrl[i];
  2468. if (!ctrl->ctrl || (ctrl == m_ctrl))
  2469. continue;
  2470. rc = dsi_phy_disable(ctrl->phy, skip_op);
  2471. if (rc)
  2472. DSI_ERR(
  2473. "[%s] failed to disable DSI PHY, skip_op=%d rc=%d\n",
  2474. display->name, skip_op, rc);
  2475. }
  2476. rc = dsi_phy_disable(m_ctrl->phy, skip_op);
  2477. if (rc)
  2478. DSI_ERR("[%s] failed to disable DSI PHY, skip_op=%d rc=%d\n",
  2479. display->name, skip_op, rc);
  2480. return rc;
  2481. }
  2482. static int dsi_display_wake_up(struct dsi_display *display)
  2483. {
  2484. return 0;
  2485. }
  2486. static void dsi_display_mask_overflow(struct dsi_display *display, u32 flags,
  2487. bool enable)
  2488. {
  2489. struct dsi_display_ctrl *ctrl;
  2490. int i;
  2491. if (!(flags & DSI_CTRL_CMD_LAST_COMMAND))
  2492. return;
  2493. display_for_each_ctrl(i, display) {
  2494. ctrl = &display->ctrl[i];
  2495. if (!ctrl)
  2496. continue;
  2497. dsi_ctrl_mask_overflow(ctrl->ctrl, enable);
  2498. }
  2499. }
  2500. static int dsi_display_broadcast_cmd(struct dsi_display *display,
  2501. const struct mipi_dsi_msg *msg)
  2502. {
  2503. int rc = 0;
  2504. u32 flags, m_flags;
  2505. struct dsi_display_ctrl *ctrl, *m_ctrl;
  2506. int i;
  2507. m_flags = (DSI_CTRL_CMD_BROADCAST | DSI_CTRL_CMD_BROADCAST_MASTER |
  2508. DSI_CTRL_CMD_DEFER_TRIGGER | DSI_CTRL_CMD_FETCH_MEMORY);
  2509. flags = (DSI_CTRL_CMD_BROADCAST | DSI_CTRL_CMD_DEFER_TRIGGER |
  2510. DSI_CTRL_CMD_FETCH_MEMORY);
  2511. if ((msg->flags & MIPI_DSI_MSG_LASTCOMMAND)) {
  2512. flags |= DSI_CTRL_CMD_LAST_COMMAND;
  2513. m_flags |= DSI_CTRL_CMD_LAST_COMMAND;
  2514. }
  2515. if ((msg->flags & MIPI_DSI_MSG_CMD_DMA_SCHED) &&
  2516. (display->panel->panel_initialized)) {
  2517. flags |= DSI_CTRL_CMD_CUSTOM_DMA_SCHED;
  2518. m_flags |= DSI_CTRL_CMD_CUSTOM_DMA_SCHED;
  2519. }
  2520. if (display->queue_cmd_waits ||
  2521. msg->flags & MIPI_DSI_MSG_ASYNC_OVERRIDE) {
  2522. flags |= DSI_CTRL_CMD_ASYNC_WAIT;
  2523. m_flags |= DSI_CTRL_CMD_ASYNC_WAIT;
  2524. }
  2525. /*
  2526. * 1. Setup commands in FIFO
  2527. * 2. Trigger commands
  2528. */
  2529. m_ctrl = &display->ctrl[display->cmd_master_idx];
  2530. dsi_display_mask_overflow(display, m_flags, true);
  2531. rc = dsi_ctrl_cmd_transfer(m_ctrl->ctrl, msg, &m_flags);
  2532. if (rc) {
  2533. DSI_ERR("[%s] cmd transfer failed on master,rc=%d\n",
  2534. display->name, rc);
  2535. goto error;
  2536. }
  2537. display_for_each_ctrl(i, display) {
  2538. ctrl = &display->ctrl[i];
  2539. if (ctrl == m_ctrl)
  2540. continue;
  2541. rc = dsi_ctrl_cmd_transfer(ctrl->ctrl, msg, &flags);
  2542. if (rc) {
  2543. DSI_ERR("[%s] cmd transfer failed, rc=%d\n",
  2544. display->name, rc);
  2545. goto error;
  2546. }
  2547. rc = dsi_ctrl_cmd_tx_trigger(ctrl->ctrl, flags);
  2548. if (rc) {
  2549. DSI_ERR("[%s] cmd trigger failed, rc=%d\n",
  2550. display->name, rc);
  2551. goto error;
  2552. }
  2553. }
  2554. rc = dsi_ctrl_cmd_tx_trigger(m_ctrl->ctrl, m_flags);
  2555. if (rc) {
  2556. DSI_ERR("[%s] cmd trigger failed for master, rc=%d\n",
  2557. display->name, rc);
  2558. goto error;
  2559. }
  2560. error:
  2561. dsi_display_mask_overflow(display, m_flags, false);
  2562. return rc;
  2563. }
  2564. static int dsi_display_phy_sw_reset(struct dsi_display *display)
  2565. {
  2566. int rc = 0;
  2567. int i;
  2568. struct dsi_display_ctrl *m_ctrl, *ctrl;
  2569. /*
  2570. * For continuous splash and trusted vm environment,
  2571. * ctrl states are updated separately and hence we do
  2572. * an early return
  2573. */
  2574. if (is_skip_op_required(display)) {
  2575. DSI_DEBUG(
  2576. "cont splash/trusted vm use case, phy sw reset not required\n");
  2577. return 0;
  2578. }
  2579. m_ctrl = &display->ctrl[display->cmd_master_idx];
  2580. rc = dsi_ctrl_phy_sw_reset(m_ctrl->ctrl);
  2581. if (rc) {
  2582. DSI_ERR("[%s] failed to reset phy, rc=%d\n", display->name, rc);
  2583. goto error;
  2584. }
  2585. display_for_each_ctrl(i, display) {
  2586. ctrl = &display->ctrl[i];
  2587. if (!ctrl->ctrl || (ctrl == m_ctrl))
  2588. continue;
  2589. rc = dsi_ctrl_phy_sw_reset(ctrl->ctrl);
  2590. if (rc) {
  2591. DSI_ERR("[%s] failed to reset phy, rc=%d\n",
  2592. display->name, rc);
  2593. goto error;
  2594. }
  2595. }
  2596. error:
  2597. return rc;
  2598. }
  2599. static int dsi_host_attach(struct mipi_dsi_host *host,
  2600. struct mipi_dsi_device *dsi)
  2601. {
  2602. return 0;
  2603. }
  2604. static int dsi_host_detach(struct mipi_dsi_host *host,
  2605. struct mipi_dsi_device *dsi)
  2606. {
  2607. return 0;
  2608. }
  2609. static ssize_t dsi_host_transfer(struct mipi_dsi_host *host,
  2610. const struct mipi_dsi_msg *msg)
  2611. {
  2612. struct dsi_display *display;
  2613. int rc = 0, ret = 0;
  2614. if (!host || !msg) {
  2615. DSI_ERR("Invalid params\n");
  2616. return 0;
  2617. }
  2618. display = to_dsi_display(host);
  2619. /* Avoid sending DCS commands when ESD recovery is pending */
  2620. if (atomic_read(&display->panel->esd_recovery_pending)) {
  2621. DSI_DEBUG("ESD recovery pending\n");
  2622. return 0;
  2623. }
  2624. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  2625. DSI_ALL_CLKS, DSI_CLK_ON);
  2626. if (rc) {
  2627. DSI_ERR("[%s] failed to enable all DSI clocks, rc=%d\n",
  2628. display->name, rc);
  2629. goto error;
  2630. }
  2631. rc = dsi_display_wake_up(display);
  2632. if (rc) {
  2633. DSI_ERR("[%s] failed to wake up display, rc=%d\n",
  2634. display->name, rc);
  2635. goto error_disable_clks;
  2636. }
  2637. rc = dsi_display_cmd_engine_enable(display);
  2638. if (rc) {
  2639. DSI_ERR("[%s] failed to enable cmd engine, rc=%d\n",
  2640. display->name, rc);
  2641. goto error_disable_clks;
  2642. }
  2643. if (display->tx_cmd_buf == NULL) {
  2644. rc = dsi_host_alloc_cmd_tx_buffer(display);
  2645. if (rc) {
  2646. DSI_ERR("failed to allocate cmd tx buffer memory\n");
  2647. goto error_disable_cmd_engine;
  2648. }
  2649. }
  2650. if (display->ctrl_count > 1 && !(msg->flags & MIPI_DSI_MSG_UNICAST)) {
  2651. rc = dsi_display_broadcast_cmd(display, msg);
  2652. if (rc) {
  2653. DSI_ERR("[%s] cmd broadcast failed, rc=%d\n",
  2654. display->name, rc);
  2655. goto error_disable_cmd_engine;
  2656. }
  2657. } else {
  2658. int ctrl_idx = (msg->flags & MIPI_DSI_MSG_UNICAST) ?
  2659. msg->ctrl : 0;
  2660. u32 cmd_flags = DSI_CTRL_CMD_FETCH_MEMORY;
  2661. if (display->queue_cmd_waits ||
  2662. msg->flags & MIPI_DSI_MSG_ASYNC_OVERRIDE)
  2663. cmd_flags |= DSI_CTRL_CMD_ASYNC_WAIT;
  2664. if ((msg->flags & MIPI_DSI_MSG_CMD_DMA_SCHED) &&
  2665. (display->panel->panel_initialized))
  2666. cmd_flags |= DSI_CTRL_CMD_CUSTOM_DMA_SCHED;
  2667. rc = dsi_ctrl_cmd_transfer(display->ctrl[ctrl_idx].ctrl, msg,
  2668. &cmd_flags);
  2669. if (rc) {
  2670. DSI_ERR("[%s] cmd transfer failed, rc=%d\n",
  2671. display->name, rc);
  2672. goto error_disable_cmd_engine;
  2673. }
  2674. }
  2675. error_disable_cmd_engine:
  2676. ret = dsi_display_cmd_engine_disable(display);
  2677. if (ret) {
  2678. DSI_ERR("[%s]failed to disable DSI cmd engine, rc=%d\n",
  2679. display->name, ret);
  2680. }
  2681. error_disable_clks:
  2682. ret = dsi_display_clk_ctrl(display->dsi_clk_handle,
  2683. DSI_ALL_CLKS, DSI_CLK_OFF);
  2684. if (ret) {
  2685. DSI_ERR("[%s] failed to disable all DSI clocks, rc=%d\n",
  2686. display->name, ret);
  2687. }
  2688. error:
  2689. return rc;
  2690. }
  2691. static struct mipi_dsi_host_ops dsi_host_ops = {
  2692. .attach = dsi_host_attach,
  2693. .detach = dsi_host_detach,
  2694. .transfer = dsi_host_transfer,
  2695. };
  2696. static int dsi_display_mipi_host_init(struct dsi_display *display)
  2697. {
  2698. int rc = 0;
  2699. struct mipi_dsi_host *host = &display->host;
  2700. host->dev = &display->pdev->dev;
  2701. host->ops = &dsi_host_ops;
  2702. rc = mipi_dsi_host_register(host);
  2703. if (rc) {
  2704. DSI_ERR("[%s] failed to register mipi dsi host, rc=%d\n",
  2705. display->name, rc);
  2706. goto error;
  2707. }
  2708. error:
  2709. return rc;
  2710. }
  2711. static int dsi_display_mipi_host_deinit(struct dsi_display *display)
  2712. {
  2713. int rc = 0;
  2714. struct mipi_dsi_host *host = &display->host;
  2715. mipi_dsi_host_unregister(host);
  2716. host->dev = NULL;
  2717. host->ops = NULL;
  2718. return rc;
  2719. }
  2720. static int dsi_display_clocks_deinit(struct dsi_display *display)
  2721. {
  2722. int rc = 0;
  2723. struct dsi_clk_link_set *src = &display->clock_info.src_clks;
  2724. struct dsi_clk_link_set *mux = &display->clock_info.mux_clks;
  2725. struct dsi_clk_link_set *shadow = &display->clock_info.shadow_clks;
  2726. if (src->byte_clk) {
  2727. devm_clk_put(&display->pdev->dev, src->byte_clk);
  2728. src->byte_clk = NULL;
  2729. }
  2730. if (src->pixel_clk) {
  2731. devm_clk_put(&display->pdev->dev, src->pixel_clk);
  2732. src->pixel_clk = NULL;
  2733. }
  2734. if (mux->byte_clk) {
  2735. devm_clk_put(&display->pdev->dev, mux->byte_clk);
  2736. mux->byte_clk = NULL;
  2737. }
  2738. if (mux->pixel_clk) {
  2739. devm_clk_put(&display->pdev->dev, mux->pixel_clk);
  2740. mux->pixel_clk = NULL;
  2741. }
  2742. if (shadow->byte_clk) {
  2743. devm_clk_put(&display->pdev->dev, shadow->byte_clk);
  2744. shadow->byte_clk = NULL;
  2745. }
  2746. if (shadow->pixel_clk) {
  2747. devm_clk_put(&display->pdev->dev, shadow->pixel_clk);
  2748. shadow->pixel_clk = NULL;
  2749. }
  2750. return rc;
  2751. }
  2752. static bool dsi_display_check_prefix(const char *clk_prefix,
  2753. const char *clk_name)
  2754. {
  2755. return !!strnstr(clk_name, clk_prefix, strlen(clk_name));
  2756. }
  2757. static int dsi_display_get_clocks_count(struct dsi_display *display,
  2758. char *dsi_clk_name)
  2759. {
  2760. if (display->fw)
  2761. return dsi_parser_count_strings(display->parser_node,
  2762. dsi_clk_name);
  2763. else
  2764. return of_property_count_strings(display->panel_node,
  2765. dsi_clk_name);
  2766. }
  2767. static void dsi_display_get_clock_name(struct dsi_display *display,
  2768. char *dsi_clk_name, int index,
  2769. const char **clk_name)
  2770. {
  2771. if (display->fw)
  2772. dsi_parser_read_string_index(display->parser_node,
  2773. dsi_clk_name, index, clk_name);
  2774. else
  2775. of_property_read_string_index(display->panel_node,
  2776. dsi_clk_name, index, clk_name);
  2777. }
  2778. static int dsi_display_clocks_init(struct dsi_display *display)
  2779. {
  2780. int i, rc = 0, num_clk = 0;
  2781. const char *clk_name;
  2782. const char *src_byte = "src_byte", *src_pixel = "src_pixel";
  2783. const char *mux_byte = "mux_byte", *mux_pixel = "mux_pixel";
  2784. const char *cphy_byte = "cphy_byte", *cphy_pixel = "cphy_pixel";
  2785. const char *shadow_byte = "shadow_byte", *shadow_pixel = "shadow_pixel";
  2786. const char *shadow_cphybyte = "shadow_cphybyte",
  2787. *shadow_cphypixel = "shadow_cphypixel";
  2788. struct clk *dsi_clk;
  2789. struct dsi_clk_link_set *src = &display->clock_info.src_clks;
  2790. struct dsi_clk_link_set *mux = &display->clock_info.mux_clks;
  2791. struct dsi_clk_link_set *cphy = &display->clock_info.cphy_clks;
  2792. struct dsi_clk_link_set *shadow = &display->clock_info.shadow_clks;
  2793. struct dsi_clk_link_set *shadow_cphy =
  2794. &display->clock_info.shadow_cphy_clks;
  2795. struct dsi_dyn_clk_caps *dyn_clk_caps = &(display->panel->dyn_clk_caps);
  2796. char *dsi_clock_name;
  2797. if (!strcmp(display->display_type, "primary"))
  2798. dsi_clock_name = "qcom,dsi-select-clocks";
  2799. else
  2800. dsi_clock_name = "qcom,dsi-select-sec-clocks";
  2801. num_clk = dsi_display_get_clocks_count(display, dsi_clock_name);
  2802. DSI_DEBUG("clk count=%d\n", num_clk);
  2803. for (i = 0; i < num_clk; i++) {
  2804. dsi_display_get_clock_name(display, dsi_clock_name, i,
  2805. &clk_name);
  2806. DSI_DEBUG("clock name:%s\n", clk_name);
  2807. dsi_clk = devm_clk_get(&display->pdev->dev, clk_name);
  2808. if (IS_ERR_OR_NULL(dsi_clk)) {
  2809. rc = PTR_ERR(dsi_clk);
  2810. DSI_ERR("failed to get %s, rc=%d\n", clk_name, rc);
  2811. if (dsi_display_check_prefix(mux_byte, clk_name)) {
  2812. mux->byte_clk = NULL;
  2813. goto error;
  2814. }
  2815. if (dsi_display_check_prefix(mux_pixel, clk_name)) {
  2816. mux->pixel_clk = NULL;
  2817. goto error;
  2818. }
  2819. if (dsi_display_check_prefix(cphy_byte, clk_name)) {
  2820. cphy->byte_clk = NULL;
  2821. goto error;
  2822. }
  2823. if (dsi_display_check_prefix(cphy_pixel, clk_name)) {
  2824. cphy->pixel_clk = NULL;
  2825. goto error;
  2826. }
  2827. if (dyn_clk_caps->dyn_clk_support &&
  2828. (display->panel->panel_mode ==
  2829. DSI_OP_VIDEO_MODE)) {
  2830. if (dsi_display_check_prefix(src_byte,
  2831. clk_name))
  2832. src->byte_clk = NULL;
  2833. if (dsi_display_check_prefix(src_pixel,
  2834. clk_name))
  2835. src->pixel_clk = NULL;
  2836. if (dsi_display_check_prefix(shadow_byte,
  2837. clk_name))
  2838. shadow->byte_clk = NULL;
  2839. if (dsi_display_check_prefix(shadow_pixel,
  2840. clk_name))
  2841. shadow->pixel_clk = NULL;
  2842. if (dsi_display_check_prefix(shadow_cphybyte,
  2843. clk_name))
  2844. shadow_cphy->byte_clk = NULL;
  2845. if (dsi_display_check_prefix(shadow_cphypixel,
  2846. clk_name))
  2847. shadow_cphy->pixel_clk = NULL;
  2848. dyn_clk_caps->dyn_clk_support = false;
  2849. }
  2850. }
  2851. if (dsi_display_check_prefix(src_byte, clk_name)) {
  2852. src->byte_clk = dsi_clk;
  2853. continue;
  2854. }
  2855. if (dsi_display_check_prefix(src_pixel, clk_name)) {
  2856. src->pixel_clk = dsi_clk;
  2857. continue;
  2858. }
  2859. if (dsi_display_check_prefix(cphy_byte, clk_name)) {
  2860. cphy->byte_clk = dsi_clk;
  2861. continue;
  2862. }
  2863. if (dsi_display_check_prefix(cphy_pixel, clk_name)) {
  2864. cphy->pixel_clk = dsi_clk;
  2865. continue;
  2866. }
  2867. if (dsi_display_check_prefix(mux_byte, clk_name)) {
  2868. mux->byte_clk = dsi_clk;
  2869. continue;
  2870. }
  2871. if (dsi_display_check_prefix(mux_pixel, clk_name)) {
  2872. mux->pixel_clk = dsi_clk;
  2873. continue;
  2874. }
  2875. if (dsi_display_check_prefix(shadow_byte, clk_name)) {
  2876. shadow->byte_clk = dsi_clk;
  2877. continue;
  2878. }
  2879. if (dsi_display_check_prefix(shadow_pixel, clk_name)) {
  2880. shadow->pixel_clk = dsi_clk;
  2881. continue;
  2882. }
  2883. if (dsi_display_check_prefix(shadow_cphybyte, clk_name)) {
  2884. shadow_cphy->byte_clk = dsi_clk;
  2885. continue;
  2886. }
  2887. if (dsi_display_check_prefix(shadow_cphypixel, clk_name)) {
  2888. shadow_cphy->pixel_clk = dsi_clk;
  2889. continue;
  2890. }
  2891. }
  2892. return 0;
  2893. error:
  2894. (void)dsi_display_clocks_deinit(display);
  2895. return rc;
  2896. }
  2897. static int dsi_display_clk_ctrl_cb(void *priv,
  2898. struct dsi_clk_ctrl_info clk_state_info)
  2899. {
  2900. int rc = 0;
  2901. struct dsi_display *display = NULL;
  2902. void *clk_handle = NULL;
  2903. if (!priv) {
  2904. DSI_ERR("Invalid params\n");
  2905. return -EINVAL;
  2906. }
  2907. display = priv;
  2908. if (clk_state_info.client == DSI_CLK_REQ_MDP_CLIENT) {
  2909. clk_handle = display->mdp_clk_handle;
  2910. } else if (clk_state_info.client == DSI_CLK_REQ_DSI_CLIENT) {
  2911. clk_handle = display->dsi_clk_handle;
  2912. } else {
  2913. DSI_ERR("invalid clk handle, return error\n");
  2914. return -EINVAL;
  2915. }
  2916. /*
  2917. * TODO: Wait for CMD_MDP_DONE interrupt if MDP client tries
  2918. * to turn off DSI clocks.
  2919. */
  2920. rc = dsi_display_clk_ctrl(clk_handle,
  2921. clk_state_info.clk_type, clk_state_info.clk_state);
  2922. if (rc) {
  2923. DSI_ERR("[%s] failed to %d DSI %d clocks, rc=%d\n",
  2924. display->name, clk_state_info.clk_state,
  2925. clk_state_info.clk_type, rc);
  2926. return rc;
  2927. }
  2928. return 0;
  2929. }
  2930. static void dsi_display_ctrl_isr_configure(struct dsi_display *display, bool en)
  2931. {
  2932. int i;
  2933. struct dsi_display_ctrl *ctrl;
  2934. if (!display)
  2935. return;
  2936. display_for_each_ctrl(i, display) {
  2937. ctrl = &display->ctrl[i];
  2938. if (!ctrl)
  2939. continue;
  2940. dsi_ctrl_isr_configure(ctrl->ctrl, en);
  2941. }
  2942. }
  2943. int dsi_pre_clkoff_cb(void *priv,
  2944. enum dsi_clk_type clk,
  2945. enum dsi_lclk_type l_type,
  2946. enum dsi_clk_state new_state)
  2947. {
  2948. int rc = 0, i;
  2949. struct dsi_display *display = priv;
  2950. struct dsi_display_ctrl *ctrl;
  2951. /*
  2952. * If Idle Power Collapse occurs immediately after a CMD
  2953. * transfer with an asynchronous wait for DMA done, ensure
  2954. * that the work queued is scheduled and completed before turning
  2955. * off the clocks and disabling interrupts to validate the command
  2956. * transfer.
  2957. */
  2958. display_for_each_ctrl(i, display) {
  2959. ctrl = &display->ctrl[i];
  2960. if (!ctrl->ctrl || !ctrl->ctrl->dma_wait_queued)
  2961. continue;
  2962. flush_workqueue(display->dma_cmd_workq);
  2963. cancel_work_sync(&ctrl->ctrl->dma_cmd_wait);
  2964. ctrl->ctrl->dma_wait_queued = false;
  2965. }
  2966. if ((clk & DSI_LINK_CLK) && (new_state == DSI_CLK_OFF) &&
  2967. (l_type & DSI_LINK_LP_CLK)) {
  2968. /*
  2969. * If continuous clock is enabled then disable it
  2970. * before entering into ULPS Mode.
  2971. */
  2972. if (display->panel->host_config.force_hs_clk_lane)
  2973. _dsi_display_continuous_clk_ctrl(display, false);
  2974. /*
  2975. * If ULPS feature is enabled, enter ULPS first.
  2976. * However, when blanking the panel, we should enter ULPS
  2977. * only if ULPS during suspend feature is enabled.
  2978. */
  2979. if (!dsi_panel_initialized(display->panel)) {
  2980. if (display->panel->ulps_suspend_enabled)
  2981. rc = dsi_display_set_ulps(display, true);
  2982. } else if (dsi_panel_ulps_feature_enabled(display->panel)) {
  2983. rc = dsi_display_set_ulps(display, true);
  2984. }
  2985. if (rc)
  2986. DSI_ERR("%s: failed enable ulps, rc = %d\n",
  2987. __func__, rc);
  2988. }
  2989. if ((clk & DSI_LINK_CLK) && (new_state == DSI_CLK_OFF) &&
  2990. (l_type & DSI_LINK_HS_CLK)) {
  2991. /*
  2992. * PHY clock gating should be disabled before the PLL and the
  2993. * branch clocks are turned off. Otherwise, it is possible that
  2994. * the clock RCGs may not be turned off correctly resulting
  2995. * in clock warnings.
  2996. */
  2997. rc = dsi_display_config_clk_gating(display, false);
  2998. if (rc)
  2999. DSI_ERR("[%s] failed to disable clk gating, rc=%d\n",
  3000. display->name, rc);
  3001. }
  3002. if ((clk & DSI_CORE_CLK) && (new_state == DSI_CLK_OFF)) {
  3003. /*
  3004. * Enable DSI clamps only if entering idle power collapse or
  3005. * when ULPS during suspend is enabled..
  3006. */
  3007. if (dsi_panel_initialized(display->panel) ||
  3008. display->panel->ulps_suspend_enabled) {
  3009. dsi_display_phy_idle_off(display);
  3010. rc = dsi_display_set_clamp(display, true);
  3011. if (rc)
  3012. DSI_ERR("%s: Failed to enable dsi clamps. rc=%d\n",
  3013. __func__, rc);
  3014. rc = dsi_display_phy_reset_config(display, false);
  3015. if (rc)
  3016. DSI_ERR("%s: Failed to reset phy, rc=%d\n",
  3017. __func__, rc);
  3018. } else {
  3019. /* Make sure that controller is not in ULPS state when
  3020. * the DSI link is not active.
  3021. */
  3022. rc = dsi_display_set_ulps(display, false);
  3023. if (rc)
  3024. DSI_ERR("%s: failed to disable ulps. rc=%d\n",
  3025. __func__, rc);
  3026. }
  3027. /* dsi will not be able to serve irqs from here on */
  3028. dsi_display_ctrl_irq_update(display, false);
  3029. /* cache the MISR values */
  3030. display_for_each_ctrl(i, display) {
  3031. ctrl = &display->ctrl[i];
  3032. if (!ctrl->ctrl)
  3033. continue;
  3034. dsi_ctrl_cache_misr(ctrl->ctrl);
  3035. }
  3036. }
  3037. return rc;
  3038. }
  3039. int dsi_post_clkon_cb(void *priv,
  3040. enum dsi_clk_type clk,
  3041. enum dsi_lclk_type l_type,
  3042. enum dsi_clk_state curr_state)
  3043. {
  3044. int rc = 0;
  3045. struct dsi_display *display = priv;
  3046. bool mmss_clamp = false;
  3047. if ((clk & DSI_LINK_CLK) && (l_type & DSI_LINK_LP_CLK)) {
  3048. mmss_clamp = display->clamp_enabled;
  3049. /*
  3050. * controller setup is needed if coming out of idle
  3051. * power collapse with clamps enabled.
  3052. */
  3053. if (mmss_clamp)
  3054. dsi_display_ctrl_setup(display);
  3055. /*
  3056. * Phy setup is needed if coming out of idle
  3057. * power collapse with clamps enabled.
  3058. */
  3059. if (display->phy_idle_power_off || mmss_clamp)
  3060. dsi_display_phy_idle_on(display, mmss_clamp);
  3061. if (display->ulps_enabled && mmss_clamp) {
  3062. /*
  3063. * ULPS Entry Request. This is needed if the lanes were
  3064. * in ULPS prior to power collapse, since after
  3065. * power collapse and reset, the DSI controller resets
  3066. * back to idle state and not ULPS. This ulps entry
  3067. * request will transition the state of the DSI
  3068. * controller to ULPS which will match the state of the
  3069. * DSI phy. This needs to be done prior to disabling
  3070. * the DSI clamps.
  3071. *
  3072. * Also, reset the ulps flag so that ulps_config
  3073. * function would reconfigure the controller state to
  3074. * ULPS.
  3075. */
  3076. display->ulps_enabled = false;
  3077. rc = dsi_display_set_ulps(display, true);
  3078. if (rc) {
  3079. DSI_ERR("%s: Failed to enter ULPS. rc=%d\n",
  3080. __func__, rc);
  3081. goto error;
  3082. }
  3083. }
  3084. rc = dsi_display_phy_reset_config(display, true);
  3085. if (rc) {
  3086. DSI_ERR("%s: Failed to reset phy, rc=%d\n",
  3087. __func__, rc);
  3088. goto error;
  3089. }
  3090. rc = dsi_display_set_clamp(display, false);
  3091. if (rc) {
  3092. DSI_ERR("%s: Failed to disable dsi clamps. rc=%d\n",
  3093. __func__, rc);
  3094. goto error;
  3095. }
  3096. }
  3097. if ((clk & DSI_LINK_CLK) && (l_type & DSI_LINK_HS_CLK)) {
  3098. /*
  3099. * Toggle the resync FIFO everytime clock changes, except
  3100. * when cont-splash screen transition is going on.
  3101. * Toggling resync FIFO during cont splash transition
  3102. * can lead to blinks on the display.
  3103. */
  3104. if (!display->is_cont_splash_enabled)
  3105. dsi_display_toggle_resync_fifo(display);
  3106. if (display->ulps_enabled) {
  3107. rc = dsi_display_set_ulps(display, false);
  3108. if (rc) {
  3109. DSI_ERR("%s: failed to disable ulps, rc= %d\n",
  3110. __func__, rc);
  3111. goto error;
  3112. }
  3113. }
  3114. if (display->panel->host_config.force_hs_clk_lane)
  3115. _dsi_display_continuous_clk_ctrl(display, true);
  3116. rc = dsi_display_config_clk_gating(display, true);
  3117. if (rc) {
  3118. DSI_ERR("[%s] failed to enable clk gating %d\n",
  3119. display->name, rc);
  3120. goto error;
  3121. }
  3122. }
  3123. /* enable dsi to serve irqs */
  3124. if (clk & DSI_CORE_CLK)
  3125. dsi_display_ctrl_irq_update(display, true);
  3126. error:
  3127. return rc;
  3128. }
  3129. int dsi_post_clkoff_cb(void *priv,
  3130. enum dsi_clk_type clk_type,
  3131. enum dsi_lclk_type l_type,
  3132. enum dsi_clk_state curr_state)
  3133. {
  3134. int rc = 0;
  3135. struct dsi_display *display = priv;
  3136. if (!display) {
  3137. DSI_ERR("%s: Invalid arg\n", __func__);
  3138. return -EINVAL;
  3139. }
  3140. if ((clk_type & DSI_CORE_CLK) &&
  3141. (curr_state == DSI_CLK_OFF)) {
  3142. rc = dsi_display_phy_power_off(display);
  3143. if (rc)
  3144. DSI_ERR("[%s] failed to power off PHY, rc=%d\n",
  3145. display->name, rc);
  3146. rc = dsi_display_ctrl_power_off(display);
  3147. if (rc)
  3148. DSI_ERR("[%s] failed to power DSI vregs, rc=%d\n",
  3149. display->name, rc);
  3150. }
  3151. return rc;
  3152. }
  3153. int dsi_pre_clkon_cb(void *priv,
  3154. enum dsi_clk_type clk_type,
  3155. enum dsi_lclk_type l_type,
  3156. enum dsi_clk_state new_state)
  3157. {
  3158. int rc = 0;
  3159. struct dsi_display *display = priv;
  3160. if (!display) {
  3161. DSI_ERR("%s: invalid input\n", __func__);
  3162. return -EINVAL;
  3163. }
  3164. if ((clk_type & DSI_CORE_CLK) && (new_state == DSI_CLK_ON)) {
  3165. /*
  3166. * Enable DSI core power
  3167. * 1.> PANEL_PM are controlled as part of
  3168. * panel_power_ctrl. Needed not be handled here.
  3169. * 2.> CTRL_PM need to be enabled/disabled
  3170. * only during unblank/blank. Their state should
  3171. * not be changed during static screen.
  3172. */
  3173. DSI_DEBUG("updating power states for ctrl and phy\n");
  3174. rc = dsi_display_ctrl_power_on(display);
  3175. if (rc) {
  3176. DSI_ERR("[%s] failed to power on dsi controllers, rc=%d\n",
  3177. display->name, rc);
  3178. return rc;
  3179. }
  3180. rc = dsi_display_phy_power_on(display);
  3181. if (rc) {
  3182. DSI_ERR("[%s] failed to power on dsi phy, rc = %d\n",
  3183. display->name, rc);
  3184. return rc;
  3185. }
  3186. DSI_DEBUG("%s: Enable DSI core power\n", __func__);
  3187. }
  3188. return rc;
  3189. }
  3190. static void __set_lane_map_v2(u8 *lane_map_v2,
  3191. enum dsi_phy_data_lanes lane0,
  3192. enum dsi_phy_data_lanes lane1,
  3193. enum dsi_phy_data_lanes lane2,
  3194. enum dsi_phy_data_lanes lane3)
  3195. {
  3196. lane_map_v2[DSI_LOGICAL_LANE_0] = lane0;
  3197. lane_map_v2[DSI_LOGICAL_LANE_1] = lane1;
  3198. lane_map_v2[DSI_LOGICAL_LANE_2] = lane2;
  3199. lane_map_v2[DSI_LOGICAL_LANE_3] = lane3;
  3200. }
  3201. static int dsi_display_parse_lane_map(struct dsi_display *display)
  3202. {
  3203. int rc = 0, i = 0;
  3204. const char *data;
  3205. u8 temp[DSI_LANE_MAX - 1];
  3206. if (!display) {
  3207. DSI_ERR("invalid params\n");
  3208. return -EINVAL;
  3209. }
  3210. /* lane-map-v2 supersedes lane-map-v1 setting */
  3211. rc = of_property_read_u8_array(display->pdev->dev.of_node,
  3212. "qcom,lane-map-v2", temp, (DSI_LANE_MAX - 1));
  3213. if (!rc) {
  3214. for (i = DSI_LOGICAL_LANE_0; i < (DSI_LANE_MAX - 1); i++)
  3215. display->lane_map.lane_map_v2[i] = BIT(temp[i]);
  3216. return 0;
  3217. } else if (rc != EINVAL) {
  3218. DSI_DEBUG("Incorrect mapping, configure default\n");
  3219. goto set_default;
  3220. }
  3221. /* lane-map older version, for DSI controller version < 2.0 */
  3222. data = of_get_property(display->pdev->dev.of_node,
  3223. "qcom,lane-map", NULL);
  3224. if (!data)
  3225. goto set_default;
  3226. if (!strcmp(data, "lane_map_3012")) {
  3227. display->lane_map.lane_map_v1 = DSI_LANE_MAP_3012;
  3228. __set_lane_map_v2(display->lane_map.lane_map_v2,
  3229. DSI_PHYSICAL_LANE_1,
  3230. DSI_PHYSICAL_LANE_2,
  3231. DSI_PHYSICAL_LANE_3,
  3232. DSI_PHYSICAL_LANE_0);
  3233. } else if (!strcmp(data, "lane_map_2301")) {
  3234. display->lane_map.lane_map_v1 = DSI_LANE_MAP_2301;
  3235. __set_lane_map_v2(display->lane_map.lane_map_v2,
  3236. DSI_PHYSICAL_LANE_2,
  3237. DSI_PHYSICAL_LANE_3,
  3238. DSI_PHYSICAL_LANE_0,
  3239. DSI_PHYSICAL_LANE_1);
  3240. } else if (!strcmp(data, "lane_map_1230")) {
  3241. display->lane_map.lane_map_v1 = DSI_LANE_MAP_1230;
  3242. __set_lane_map_v2(display->lane_map.lane_map_v2,
  3243. DSI_PHYSICAL_LANE_3,
  3244. DSI_PHYSICAL_LANE_0,
  3245. DSI_PHYSICAL_LANE_1,
  3246. DSI_PHYSICAL_LANE_2);
  3247. } else if (!strcmp(data, "lane_map_0321")) {
  3248. display->lane_map.lane_map_v1 = DSI_LANE_MAP_0321;
  3249. __set_lane_map_v2(display->lane_map.lane_map_v2,
  3250. DSI_PHYSICAL_LANE_0,
  3251. DSI_PHYSICAL_LANE_3,
  3252. DSI_PHYSICAL_LANE_2,
  3253. DSI_PHYSICAL_LANE_1);
  3254. } else if (!strcmp(data, "lane_map_1032")) {
  3255. display->lane_map.lane_map_v1 = DSI_LANE_MAP_1032;
  3256. __set_lane_map_v2(display->lane_map.lane_map_v2,
  3257. DSI_PHYSICAL_LANE_1,
  3258. DSI_PHYSICAL_LANE_0,
  3259. DSI_PHYSICAL_LANE_3,
  3260. DSI_PHYSICAL_LANE_2);
  3261. } else if (!strcmp(data, "lane_map_2103")) {
  3262. display->lane_map.lane_map_v1 = DSI_LANE_MAP_2103;
  3263. __set_lane_map_v2(display->lane_map.lane_map_v2,
  3264. DSI_PHYSICAL_LANE_2,
  3265. DSI_PHYSICAL_LANE_1,
  3266. DSI_PHYSICAL_LANE_0,
  3267. DSI_PHYSICAL_LANE_3);
  3268. } else if (!strcmp(data, "lane_map_3210")) {
  3269. display->lane_map.lane_map_v1 = DSI_LANE_MAP_3210;
  3270. __set_lane_map_v2(display->lane_map.lane_map_v2,
  3271. DSI_PHYSICAL_LANE_3,
  3272. DSI_PHYSICAL_LANE_2,
  3273. DSI_PHYSICAL_LANE_1,
  3274. DSI_PHYSICAL_LANE_0);
  3275. } else {
  3276. DSI_WARN("%s: invalid lane map %s specified. defaulting to lane_map0123\n",
  3277. __func__, data);
  3278. goto set_default;
  3279. }
  3280. return 0;
  3281. set_default:
  3282. /* default lane mapping */
  3283. __set_lane_map_v2(display->lane_map.lane_map_v2, DSI_PHYSICAL_LANE_0,
  3284. DSI_PHYSICAL_LANE_1, DSI_PHYSICAL_LANE_2, DSI_PHYSICAL_LANE_3);
  3285. display->lane_map.lane_map_v1 = DSI_LANE_MAP_0123;
  3286. return 0;
  3287. }
  3288. static int dsi_display_get_phandle_index(
  3289. struct dsi_display *display,
  3290. const char *propname, int count, int index)
  3291. {
  3292. struct device_node *disp_node = display->panel_node;
  3293. u32 *val = NULL;
  3294. int rc = 0;
  3295. val = kcalloc(count, sizeof(*val), GFP_KERNEL);
  3296. if (ZERO_OR_NULL_PTR(val)) {
  3297. rc = -ENOMEM;
  3298. goto end;
  3299. }
  3300. if (index >= count)
  3301. goto end;
  3302. if (display->fw)
  3303. rc = dsi_parser_read_u32_array(display->parser_node,
  3304. propname, val, count);
  3305. else
  3306. rc = of_property_read_u32_array(disp_node, propname,
  3307. val, count);
  3308. if (rc)
  3309. goto end;
  3310. rc = val[index];
  3311. DSI_DEBUG("%s index=%d\n", propname, rc);
  3312. end:
  3313. kfree(val);
  3314. return rc;
  3315. }
  3316. static int dsi_display_get_phandle_count(struct dsi_display *display,
  3317. const char *propname)
  3318. {
  3319. if (display->fw)
  3320. return dsi_parser_count_u32_elems(display->parser_node,
  3321. propname);
  3322. else
  3323. return of_property_count_u32_elems(display->panel_node,
  3324. propname);
  3325. }
  3326. static int dsi_display_parse_dt(struct dsi_display *display)
  3327. {
  3328. int i, rc = 0;
  3329. u32 phy_count = 0;
  3330. struct device_node *of_node = display->pdev->dev.of_node;
  3331. char *dsi_ctrl_name, *dsi_phy_name;
  3332. if (!strcmp(display->display_type, "primary")) {
  3333. dsi_ctrl_name = "qcom,dsi-ctrl-num";
  3334. dsi_phy_name = "qcom,dsi-phy-num";
  3335. } else {
  3336. dsi_ctrl_name = "qcom,dsi-sec-ctrl-num";
  3337. dsi_phy_name = "qcom,dsi-sec-phy-num";
  3338. }
  3339. display->ctrl_count = dsi_display_get_phandle_count(display,
  3340. dsi_ctrl_name);
  3341. phy_count = dsi_display_get_phandle_count(display, dsi_phy_name);
  3342. DSI_DEBUG("ctrl count=%d, phy count=%d\n",
  3343. display->ctrl_count, phy_count);
  3344. if (!phy_count || !display->ctrl_count) {
  3345. DSI_ERR("no ctrl/phys found\n");
  3346. rc = -ENODEV;
  3347. goto error;
  3348. }
  3349. if (phy_count != display->ctrl_count) {
  3350. DSI_ERR("different ctrl and phy counts\n");
  3351. rc = -ENODEV;
  3352. goto error;
  3353. }
  3354. display_for_each_ctrl(i, display) {
  3355. struct dsi_display_ctrl *ctrl = &display->ctrl[i];
  3356. int index;
  3357. index = dsi_display_get_phandle_index(display, dsi_ctrl_name,
  3358. display->ctrl_count, i);
  3359. ctrl->ctrl_of_node = of_parse_phandle(of_node,
  3360. "qcom,dsi-ctrl", index);
  3361. of_node_put(ctrl->ctrl_of_node);
  3362. index = dsi_display_get_phandle_index(display, dsi_phy_name,
  3363. display->ctrl_count, i);
  3364. ctrl->phy_of_node = of_parse_phandle(of_node,
  3365. "qcom,dsi-phy", index);
  3366. of_node_put(ctrl->phy_of_node);
  3367. }
  3368. /* Parse TE data */
  3369. dsi_display_parse_te_data(display);
  3370. /* Parse all external bridges from port 0 */
  3371. display_for_each_ctrl(i, display) {
  3372. display->ext_bridge[i].node_of =
  3373. of_graph_get_remote_node(of_node, 0, i);
  3374. if (display->ext_bridge[i].node_of)
  3375. display->ext_bridge_cnt++;
  3376. else
  3377. break;
  3378. }
  3379. DSI_DEBUG("success\n");
  3380. error:
  3381. return rc;
  3382. }
  3383. static int dsi_display_res_init(struct dsi_display *display)
  3384. {
  3385. int rc = 0;
  3386. int i;
  3387. struct dsi_display_ctrl *ctrl;
  3388. display_for_each_ctrl(i, display) {
  3389. ctrl = &display->ctrl[i];
  3390. ctrl->ctrl = dsi_ctrl_get(ctrl->ctrl_of_node);
  3391. if (IS_ERR_OR_NULL(ctrl->ctrl)) {
  3392. rc = PTR_ERR(ctrl->ctrl);
  3393. DSI_ERR("failed to get dsi controller, rc=%d\n", rc);
  3394. ctrl->ctrl = NULL;
  3395. goto error_ctrl_put;
  3396. }
  3397. ctrl->phy = dsi_phy_get(ctrl->phy_of_node);
  3398. if (IS_ERR_OR_NULL(ctrl->phy)) {
  3399. rc = PTR_ERR(ctrl->phy);
  3400. DSI_ERR("failed to get phy controller, rc=%d\n", rc);
  3401. dsi_ctrl_put(ctrl->ctrl);
  3402. ctrl->phy = NULL;
  3403. goto error_ctrl_put;
  3404. }
  3405. }
  3406. display->panel = dsi_panel_get(&display->pdev->dev,
  3407. display->panel_node,
  3408. display->parser_node,
  3409. display->display_type,
  3410. display->cmdline_topology,
  3411. display->trusted_vm_env);
  3412. if (IS_ERR_OR_NULL(display->panel)) {
  3413. rc = PTR_ERR(display->panel);
  3414. DSI_ERR("failed to get panel, rc=%d\n", rc);
  3415. display->panel = NULL;
  3416. goto error_ctrl_put;
  3417. }
  3418. display_for_each_ctrl(i, display) {
  3419. struct msm_dsi_phy *phy = display->ctrl[i].phy;
  3420. phy->cfg.force_clk_lane_hs =
  3421. display->panel->host_config.force_hs_clk_lane;
  3422. phy->cfg.phy_type =
  3423. display->panel->host_config.phy_type;
  3424. }
  3425. rc = dsi_display_parse_lane_map(display);
  3426. if (rc) {
  3427. DSI_ERR("Lane map not found, rc=%d\n", rc);
  3428. goto error_ctrl_put;
  3429. }
  3430. rc = dsi_display_clocks_init(display);
  3431. if (rc) {
  3432. DSI_ERR("Failed to parse clock data, rc=%d\n", rc);
  3433. goto error_ctrl_put;
  3434. }
  3435. /**
  3436. * In trusted vm, the connectors will not be enabled
  3437. * until the HW resources are assigned and accepted.
  3438. */
  3439. if (display->trusted_vm_env)
  3440. display->is_active = false;
  3441. else
  3442. display->is_active = true;
  3443. return 0;
  3444. error_ctrl_put:
  3445. for (i = i - 1; i >= 0; i--) {
  3446. ctrl = &display->ctrl[i];
  3447. dsi_ctrl_put(ctrl->ctrl);
  3448. dsi_phy_put(ctrl->phy);
  3449. }
  3450. return rc;
  3451. }
  3452. static int dsi_display_res_deinit(struct dsi_display *display)
  3453. {
  3454. int rc = 0;
  3455. int i;
  3456. struct dsi_display_ctrl *ctrl;
  3457. rc = dsi_display_clocks_deinit(display);
  3458. if (rc)
  3459. DSI_ERR("clocks deinit failed, rc=%d\n", rc);
  3460. display_for_each_ctrl(i, display) {
  3461. ctrl = &display->ctrl[i];
  3462. dsi_phy_put(ctrl->phy);
  3463. dsi_ctrl_put(ctrl->ctrl);
  3464. }
  3465. if (display->panel)
  3466. dsi_panel_put(display->panel);
  3467. return rc;
  3468. }
  3469. static int dsi_display_validate_mode_set(struct dsi_display *display,
  3470. struct dsi_display_mode *mode,
  3471. u32 flags)
  3472. {
  3473. int rc = 0;
  3474. int i;
  3475. struct dsi_display_ctrl *ctrl;
  3476. /*
  3477. * To set a mode:
  3478. * 1. Controllers should be turned off.
  3479. * 2. Link clocks should be off.
  3480. * 3. Phy should be disabled.
  3481. */
  3482. display_for_each_ctrl(i, display) {
  3483. ctrl = &display->ctrl[i];
  3484. if ((ctrl->power_state > DSI_CTRL_POWER_VREG_ON) ||
  3485. (ctrl->phy_enabled)) {
  3486. rc = -EINVAL;
  3487. goto error;
  3488. }
  3489. }
  3490. error:
  3491. return rc;
  3492. }
  3493. static bool dsi_display_is_seamless_dfps_possible(
  3494. const struct dsi_display *display,
  3495. const struct dsi_display_mode *tgt,
  3496. const enum dsi_dfps_type dfps_type)
  3497. {
  3498. struct dsi_display_mode *cur;
  3499. if (!display || !tgt || !display->panel) {
  3500. DSI_ERR("Invalid params\n");
  3501. return false;
  3502. }
  3503. cur = display->panel->cur_mode;
  3504. if (cur->timing.h_active != tgt->timing.h_active) {
  3505. DSI_DEBUG("timing.h_active differs %d %d\n",
  3506. cur->timing.h_active, tgt->timing.h_active);
  3507. return false;
  3508. }
  3509. if (cur->timing.h_back_porch != tgt->timing.h_back_porch) {
  3510. DSI_DEBUG("timing.h_back_porch differs %d %d\n",
  3511. cur->timing.h_back_porch,
  3512. tgt->timing.h_back_porch);
  3513. return false;
  3514. }
  3515. if (cur->timing.h_sync_width != tgt->timing.h_sync_width) {
  3516. DSI_DEBUG("timing.h_sync_width differs %d %d\n",
  3517. cur->timing.h_sync_width,
  3518. tgt->timing.h_sync_width);
  3519. return false;
  3520. }
  3521. if (cur->timing.h_front_porch != tgt->timing.h_front_porch) {
  3522. DSI_DEBUG("timing.h_front_porch differs %d %d\n",
  3523. cur->timing.h_front_porch,
  3524. tgt->timing.h_front_porch);
  3525. if (dfps_type != DSI_DFPS_IMMEDIATE_HFP)
  3526. return false;
  3527. }
  3528. if (cur->timing.h_skew != tgt->timing.h_skew) {
  3529. DSI_DEBUG("timing.h_skew differs %d %d\n",
  3530. cur->timing.h_skew,
  3531. tgt->timing.h_skew);
  3532. return false;
  3533. }
  3534. /* skip polarity comparison */
  3535. if (cur->timing.v_active != tgt->timing.v_active) {
  3536. DSI_DEBUG("timing.v_active differs %d %d\n",
  3537. cur->timing.v_active,
  3538. tgt->timing.v_active);
  3539. return false;
  3540. }
  3541. if (cur->timing.v_back_porch != tgt->timing.v_back_porch) {
  3542. DSI_DEBUG("timing.v_back_porch differs %d %d\n",
  3543. cur->timing.v_back_porch,
  3544. tgt->timing.v_back_porch);
  3545. return false;
  3546. }
  3547. if (cur->timing.v_sync_width != tgt->timing.v_sync_width) {
  3548. DSI_DEBUG("timing.v_sync_width differs %d %d\n",
  3549. cur->timing.v_sync_width,
  3550. tgt->timing.v_sync_width);
  3551. return false;
  3552. }
  3553. if (cur->timing.v_front_porch != tgt->timing.v_front_porch) {
  3554. DSI_DEBUG("timing.v_front_porch differs %d %d\n",
  3555. cur->timing.v_front_porch,
  3556. tgt->timing.v_front_porch);
  3557. if (dfps_type != DSI_DFPS_IMMEDIATE_VFP)
  3558. return false;
  3559. }
  3560. /* skip polarity comparison */
  3561. if (cur->timing.refresh_rate == tgt->timing.refresh_rate)
  3562. DSI_DEBUG("timing.refresh_rate identical %d %d\n",
  3563. cur->timing.refresh_rate,
  3564. tgt->timing.refresh_rate);
  3565. if (cur->pixel_clk_khz != tgt->pixel_clk_khz)
  3566. DSI_DEBUG("pixel_clk_khz differs %d %d\n",
  3567. cur->pixel_clk_khz, tgt->pixel_clk_khz);
  3568. if (cur->dsi_mode_flags != tgt->dsi_mode_flags)
  3569. DSI_DEBUG("flags differs %d %d\n",
  3570. cur->dsi_mode_flags, tgt->dsi_mode_flags);
  3571. return true;
  3572. }
  3573. void dsi_display_update_byte_intf_div(struct dsi_display *display)
  3574. {
  3575. struct dsi_host_common_cfg *config;
  3576. struct dsi_display_ctrl *m_ctrl;
  3577. int phy_ver;
  3578. m_ctrl = &display->ctrl[display->cmd_master_idx];
  3579. config = &display->panel->host_config;
  3580. phy_ver = dsi_phy_get_version(m_ctrl->phy);
  3581. if (phy_ver <= DSI_PHY_VERSION_2_0)
  3582. config->byte_intf_clk_div = 1;
  3583. else
  3584. config->byte_intf_clk_div = 2;
  3585. }
  3586. static int dsi_display_update_dsi_bitrate(struct dsi_display *display,
  3587. u32 bit_clk_rate)
  3588. {
  3589. int rc = 0;
  3590. int i;
  3591. DSI_DEBUG("%s:bit rate:%d\n", __func__, bit_clk_rate);
  3592. if (!display->panel) {
  3593. DSI_ERR("Invalid params\n");
  3594. return -EINVAL;
  3595. }
  3596. if (bit_clk_rate == 0) {
  3597. DSI_ERR("Invalid bit clock rate\n");
  3598. return -EINVAL;
  3599. }
  3600. display->config.bit_clk_rate_hz = bit_clk_rate;
  3601. display_for_each_ctrl(i, display) {
  3602. struct dsi_display_ctrl *dsi_disp_ctrl = &display->ctrl[i];
  3603. struct dsi_ctrl *ctrl = dsi_disp_ctrl->ctrl;
  3604. u32 num_of_lanes = 0, bpp, byte_intf_clk_div;
  3605. u64 bit_rate, pclk_rate, bit_rate_per_lane, byte_clk_rate,
  3606. byte_intf_clk_rate;
  3607. u32 bits_per_symbol = 16, num_of_symbols = 7; /* For Cphy */
  3608. struct dsi_host_common_cfg *host_cfg;
  3609. mutex_lock(&ctrl->ctrl_lock);
  3610. host_cfg = &display->panel->host_config;
  3611. if (host_cfg->data_lanes & DSI_DATA_LANE_0)
  3612. num_of_lanes++;
  3613. if (host_cfg->data_lanes & DSI_DATA_LANE_1)
  3614. num_of_lanes++;
  3615. if (host_cfg->data_lanes & DSI_DATA_LANE_2)
  3616. num_of_lanes++;
  3617. if (host_cfg->data_lanes & DSI_DATA_LANE_3)
  3618. num_of_lanes++;
  3619. if (num_of_lanes == 0) {
  3620. DSI_ERR("Invalid lane count\n");
  3621. rc = -EINVAL;
  3622. goto error;
  3623. }
  3624. bpp = dsi_pixel_format_to_bpp(host_cfg->dst_format);
  3625. bit_rate = display->config.bit_clk_rate_hz * num_of_lanes;
  3626. bit_rate_per_lane = bit_rate;
  3627. do_div(bit_rate_per_lane, num_of_lanes);
  3628. pclk_rate = bit_rate;
  3629. do_div(pclk_rate, bpp);
  3630. if (host_cfg->phy_type == DSI_PHY_TYPE_DPHY) {
  3631. bit_rate_per_lane = bit_rate;
  3632. do_div(bit_rate_per_lane, num_of_lanes);
  3633. byte_clk_rate = bit_rate_per_lane;
  3634. do_div(byte_clk_rate, 8);
  3635. byte_intf_clk_rate = byte_clk_rate;
  3636. byte_intf_clk_div = host_cfg->byte_intf_clk_div;
  3637. do_div(byte_intf_clk_rate, byte_intf_clk_div);
  3638. } else {
  3639. bit_rate_per_lane = bit_clk_rate;
  3640. pclk_rate *= bits_per_symbol;
  3641. do_div(pclk_rate, num_of_symbols);
  3642. byte_clk_rate = bit_clk_rate;
  3643. do_div(byte_clk_rate, num_of_symbols);
  3644. /* For CPHY, byte_intf_clk is same as byte_clk */
  3645. byte_intf_clk_rate = byte_clk_rate;
  3646. }
  3647. DSI_DEBUG("bit_clk_rate = %llu, bit_clk_rate_per_lane = %llu\n",
  3648. bit_rate, bit_rate_per_lane);
  3649. DSI_DEBUG("byte_clk_rate = %llu, byte_intf_clk_rate = %llu\n",
  3650. byte_clk_rate, byte_intf_clk_rate);
  3651. DSI_DEBUG("pclk_rate = %llu\n", pclk_rate);
  3652. SDE_EVT32(i, bit_rate, byte_clk_rate, pclk_rate);
  3653. ctrl->clk_freq.byte_clk_rate = byte_clk_rate;
  3654. ctrl->clk_freq.byte_intf_clk_rate = byte_intf_clk_rate;
  3655. ctrl->clk_freq.pix_clk_rate = pclk_rate;
  3656. rc = dsi_clk_set_link_frequencies(display->dsi_clk_handle,
  3657. ctrl->clk_freq, ctrl->cell_index);
  3658. if (rc) {
  3659. DSI_ERR("Failed to update link frequencies\n");
  3660. goto error;
  3661. }
  3662. ctrl->host_config.bit_clk_rate_hz = bit_clk_rate;
  3663. error:
  3664. mutex_unlock(&ctrl->ctrl_lock);
  3665. /* TODO: recover ctrl->clk_freq in case of failure */
  3666. if (rc)
  3667. return rc;
  3668. }
  3669. return 0;
  3670. }
  3671. static void _dsi_display_calc_pipe_delay(struct dsi_display *display,
  3672. struct dsi_dyn_clk_delay *delay,
  3673. struct dsi_display_mode *mode)
  3674. {
  3675. u32 esc_clk_rate_hz;
  3676. u32 pclk_to_esc_ratio, byte_to_esc_ratio, hr_bit_to_esc_ratio;
  3677. u32 hsync_period = 0;
  3678. struct dsi_display_ctrl *m_ctrl;
  3679. struct dsi_ctrl *dsi_ctrl;
  3680. struct dsi_phy_cfg *cfg;
  3681. int phy_ver;
  3682. m_ctrl = &display->ctrl[display->clk_master_idx];
  3683. dsi_ctrl = m_ctrl->ctrl;
  3684. cfg = &(m_ctrl->phy->cfg);
  3685. esc_clk_rate_hz = dsi_ctrl->clk_freq.esc_clk_rate;
  3686. pclk_to_esc_ratio = (dsi_ctrl->clk_freq.pix_clk_rate /
  3687. esc_clk_rate_hz);
  3688. byte_to_esc_ratio = (dsi_ctrl->clk_freq.byte_clk_rate /
  3689. esc_clk_rate_hz);
  3690. hr_bit_to_esc_ratio = ((dsi_ctrl->clk_freq.byte_clk_rate * 4) /
  3691. esc_clk_rate_hz);
  3692. hsync_period = dsi_h_total_dce(&mode->timing);
  3693. delay->pipe_delay = (hsync_period + 1) / pclk_to_esc_ratio;
  3694. if (!display->panel->video_config.eof_bllp_lp11_en)
  3695. delay->pipe_delay += (17 / pclk_to_esc_ratio) +
  3696. ((21 + (display->config.common_config.t_clk_pre + 1) +
  3697. (display->config.common_config.t_clk_post + 1)) /
  3698. byte_to_esc_ratio) +
  3699. ((((cfg->timing.lane_v3[8] >> 1) + 1) +
  3700. ((cfg->timing.lane_v3[6] >> 1) + 1) +
  3701. ((cfg->timing.lane_v3[3] * 4) +
  3702. (cfg->timing.lane_v3[5] >> 1) + 1) +
  3703. ((cfg->timing.lane_v3[7] >> 1) + 1) +
  3704. ((cfg->timing.lane_v3[1] >> 1) + 1) +
  3705. ((cfg->timing.lane_v3[4] >> 1) + 1)) /
  3706. hr_bit_to_esc_ratio);
  3707. delay->pipe_delay2 = 0;
  3708. if (display->panel->host_config.force_hs_clk_lane)
  3709. delay->pipe_delay2 = (6 / byte_to_esc_ratio) +
  3710. ((((cfg->timing.lane_v3[1] >> 1) + 1) +
  3711. ((cfg->timing.lane_v3[4] >> 1) + 1)) /
  3712. hr_bit_to_esc_ratio);
  3713. /*
  3714. * 100us pll delay recommended for phy ver 2.0 and 3.0
  3715. * 25us pll delay recommended for phy ver 4.0
  3716. */
  3717. phy_ver = dsi_phy_get_version(m_ctrl->phy);
  3718. if (phy_ver <= DSI_PHY_VERSION_3_0)
  3719. delay->pll_delay = 100;
  3720. else
  3721. delay->pll_delay = 25;
  3722. delay->pll_delay = ((delay->pll_delay * esc_clk_rate_hz) / 1000000);
  3723. }
  3724. /*
  3725. * dsi_display_is_type_cphy - check if panel type is cphy
  3726. * @display: Pointer to private display structure
  3727. * Returns: True if panel type is cphy
  3728. */
  3729. static inline bool dsi_display_is_type_cphy(struct dsi_display *display)
  3730. {
  3731. return (display->panel->host_config.phy_type ==
  3732. DSI_PHY_TYPE_CPHY) ? true : false;
  3733. }
  3734. static int _dsi_display_dyn_update_clks(struct dsi_display *display,
  3735. struct link_clk_freq *bkp_freq)
  3736. {
  3737. int rc = 0, i;
  3738. u8 ctrl_version;
  3739. struct dsi_display_ctrl *m_ctrl, *ctrl;
  3740. struct dsi_dyn_clk_caps *dyn_clk_caps;
  3741. struct dsi_clk_link_set *parent_clk, *enable_clk;
  3742. m_ctrl = &display->ctrl[display->clk_master_idx];
  3743. dyn_clk_caps = &(display->panel->dyn_clk_caps);
  3744. ctrl_version = m_ctrl->ctrl->version;
  3745. if (dsi_display_is_type_cphy(display)) {
  3746. enable_clk = &display->clock_info.cphy_clks;
  3747. parent_clk = &display->clock_info.shadow_cphy_clks;
  3748. } else {
  3749. enable_clk = &display->clock_info.src_clks;
  3750. parent_clk = &display->clock_info.shadow_clks;
  3751. }
  3752. dsi_clk_prepare_enable(enable_clk);
  3753. rc = dsi_clk_update_parent(parent_clk,
  3754. &display->clock_info.mux_clks);
  3755. if (rc) {
  3756. DSI_ERR("failed to update mux parent\n");
  3757. goto exit;
  3758. }
  3759. display_for_each_ctrl(i, display) {
  3760. ctrl = &display->ctrl[i];
  3761. if (!ctrl->ctrl)
  3762. continue;
  3763. rc = dsi_clk_set_byte_clk_rate(display->dsi_clk_handle,
  3764. ctrl->ctrl->clk_freq.byte_clk_rate,
  3765. ctrl->ctrl->clk_freq.byte_intf_clk_rate, i);
  3766. if (rc) {
  3767. DSI_ERR("failed to set byte rate for index:%d\n", i);
  3768. goto recover_byte_clk;
  3769. }
  3770. rc = dsi_clk_set_pixel_clk_rate(display->dsi_clk_handle,
  3771. ctrl->ctrl->clk_freq.pix_clk_rate, i);
  3772. if (rc) {
  3773. DSI_ERR("failed to set pix rate for index:%d\n", i);
  3774. goto recover_pix_clk;
  3775. }
  3776. }
  3777. display_for_each_ctrl(i, display) {
  3778. ctrl = &display->ctrl[i];
  3779. if (ctrl == m_ctrl)
  3780. continue;
  3781. dsi_phy_dynamic_refresh_trigger(ctrl->phy, false);
  3782. }
  3783. dsi_phy_dynamic_refresh_trigger(m_ctrl->phy, true);
  3784. /*
  3785. * Don't wait for dynamic refresh done for dsi ctrl greater than 2.5
  3786. * and with constant fps, as dynamic refresh will applied with
  3787. * next mdp intf ctrl flush.
  3788. */
  3789. if ((ctrl_version >= DSI_CTRL_VERSION_2_5) &&
  3790. (dyn_clk_caps->maintain_const_fps))
  3791. goto defer_dfps_wait;
  3792. /* wait for dynamic refresh done */
  3793. display_for_each_ctrl(i, display) {
  3794. ctrl = &display->ctrl[i];
  3795. rc = dsi_ctrl_wait4dynamic_refresh_done(ctrl->ctrl);
  3796. if (rc) {
  3797. DSI_ERR("wait4dynamic refresh failed for dsi:%d\n", i);
  3798. goto recover_pix_clk;
  3799. } else {
  3800. DSI_INFO("dynamic refresh done on dsi: %s\n",
  3801. i ? "slave" : "master");
  3802. }
  3803. }
  3804. display_for_each_ctrl(i, display) {
  3805. ctrl = &display->ctrl[i];
  3806. dsi_phy_dynamic_refresh_clear(ctrl->phy);
  3807. }
  3808. defer_dfps_wait:
  3809. rc = dsi_clk_update_parent(enable_clk,
  3810. &display->clock_info.mux_clks);
  3811. if (rc)
  3812. DSI_ERR("could not switch back to src clks %d\n", rc);
  3813. dsi_clk_disable_unprepare(enable_clk);
  3814. return rc;
  3815. recover_pix_clk:
  3816. display_for_each_ctrl(i, display) {
  3817. ctrl = &display->ctrl[i];
  3818. if (!ctrl->ctrl)
  3819. continue;
  3820. dsi_clk_set_pixel_clk_rate(display->dsi_clk_handle,
  3821. bkp_freq->pix_clk_rate, i);
  3822. }
  3823. recover_byte_clk:
  3824. display_for_each_ctrl(i, display) {
  3825. ctrl = &display->ctrl[i];
  3826. if (!ctrl->ctrl)
  3827. continue;
  3828. dsi_clk_set_byte_clk_rate(display->dsi_clk_handle,
  3829. bkp_freq->byte_clk_rate,
  3830. bkp_freq->byte_intf_clk_rate, i);
  3831. }
  3832. exit:
  3833. dsi_clk_disable_unprepare(&display->clock_info.src_clks);
  3834. return rc;
  3835. }
  3836. static int dsi_display_dynamic_clk_switch_vid(struct dsi_display *display,
  3837. struct dsi_display_mode *mode)
  3838. {
  3839. int rc = 0, mask, i;
  3840. struct dsi_display_ctrl *m_ctrl, *ctrl;
  3841. struct dsi_dyn_clk_delay delay;
  3842. struct link_clk_freq bkp_freq;
  3843. dsi_panel_acquire_panel_lock(display->panel);
  3844. m_ctrl = &display->ctrl[display->clk_master_idx];
  3845. dsi_display_clk_ctrl(display->dsi_clk_handle, DSI_ALL_CLKS, DSI_CLK_ON);
  3846. /* mask PLL unlock, FIFO overflow and underflow errors */
  3847. mask = BIT(DSI_PLL_UNLOCK_ERR) | BIT(DSI_FIFO_UNDERFLOW) |
  3848. BIT(DSI_FIFO_OVERFLOW);
  3849. dsi_display_mask_ctrl_error_interrupts(display, mask, true);
  3850. /* update the phy timings based on new mode */
  3851. display_for_each_ctrl(i, display) {
  3852. ctrl = &display->ctrl[i];
  3853. dsi_phy_update_phy_timings(ctrl->phy, &display->config);
  3854. }
  3855. /* back up existing rates to handle failure case */
  3856. bkp_freq.byte_clk_rate = m_ctrl->ctrl->clk_freq.byte_clk_rate;
  3857. bkp_freq.byte_intf_clk_rate = m_ctrl->ctrl->clk_freq.byte_intf_clk_rate;
  3858. bkp_freq.pix_clk_rate = m_ctrl->ctrl->clk_freq.pix_clk_rate;
  3859. bkp_freq.esc_clk_rate = m_ctrl->ctrl->clk_freq.esc_clk_rate;
  3860. rc = dsi_display_update_dsi_bitrate(display, mode->timing.clk_rate_hz);
  3861. if (rc) {
  3862. DSI_ERR("failed set link frequencies %d\n", rc);
  3863. goto exit;
  3864. }
  3865. /* calculate pipe delays */
  3866. _dsi_display_calc_pipe_delay(display, &delay, mode);
  3867. /* configure dynamic refresh ctrl registers */
  3868. display_for_each_ctrl(i, display) {
  3869. ctrl = &display->ctrl[i];
  3870. if (!ctrl->phy)
  3871. continue;
  3872. if (ctrl == m_ctrl)
  3873. dsi_phy_config_dynamic_refresh(ctrl->phy, &delay, true);
  3874. else
  3875. dsi_phy_config_dynamic_refresh(ctrl->phy, &delay,
  3876. false);
  3877. }
  3878. rc = _dsi_display_dyn_update_clks(display, &bkp_freq);
  3879. exit:
  3880. dsi_display_mask_ctrl_error_interrupts(display, mask, false);
  3881. dsi_display_clk_ctrl(display->dsi_clk_handle, DSI_ALL_CLKS,
  3882. DSI_CLK_OFF);
  3883. /* store newly calculated phy timings in mode private info */
  3884. dsi_phy_dyn_refresh_cache_phy_timings(m_ctrl->phy,
  3885. mode->priv_info->phy_timing_val,
  3886. mode->priv_info->phy_timing_len);
  3887. dsi_panel_release_panel_lock(display->panel);
  3888. return rc;
  3889. }
  3890. static int dsi_display_dynamic_clk_configure_cmd(struct dsi_display *display,
  3891. int clk_rate)
  3892. {
  3893. int rc = 0;
  3894. if (clk_rate <= 0) {
  3895. DSI_ERR("%s: bitrate should be greater than 0\n", __func__);
  3896. return -EINVAL;
  3897. }
  3898. if (clk_rate == display->cached_clk_rate) {
  3899. DSI_INFO("%s: ignore duplicated DSI clk setting\n", __func__);
  3900. return rc;
  3901. }
  3902. display->cached_clk_rate = clk_rate;
  3903. rc = dsi_display_update_dsi_bitrate(display, clk_rate);
  3904. if (!rc) {
  3905. DSI_INFO("%s: bit clk is ready to be configured to '%d'\n",
  3906. __func__, clk_rate);
  3907. atomic_set(&display->clkrate_change_pending, 1);
  3908. } else {
  3909. DSI_ERR("%s: Failed to prepare to configure '%d'. rc = %d\n",
  3910. __func__, clk_rate, rc);
  3911. /* Caching clock failed, so don't go on doing so. */
  3912. atomic_set(&display->clkrate_change_pending, 0);
  3913. display->cached_clk_rate = 0;
  3914. }
  3915. return rc;
  3916. }
  3917. static int dsi_display_dfps_update(struct dsi_display *display,
  3918. struct dsi_display_mode *dsi_mode)
  3919. {
  3920. struct dsi_mode_info *timing;
  3921. struct dsi_display_ctrl *m_ctrl, *ctrl;
  3922. struct dsi_display_mode *panel_mode;
  3923. struct dsi_dfps_capabilities dfps_caps;
  3924. int rc = 0;
  3925. int i = 0;
  3926. struct dsi_dyn_clk_caps *dyn_clk_caps;
  3927. if (!display || !dsi_mode || !display->panel) {
  3928. DSI_ERR("Invalid params\n");
  3929. return -EINVAL;
  3930. }
  3931. timing = &dsi_mode->timing;
  3932. dsi_panel_get_dfps_caps(display->panel, &dfps_caps);
  3933. dyn_clk_caps = &(display->panel->dyn_clk_caps);
  3934. if (!dfps_caps.dfps_support && !dyn_clk_caps->maintain_const_fps) {
  3935. DSI_ERR("dfps or constant fps not supported\n");
  3936. return -ENOTSUPP;
  3937. }
  3938. if (dfps_caps.type == DSI_DFPS_IMMEDIATE_CLK) {
  3939. DSI_ERR("dfps clock method not supported\n");
  3940. return -ENOTSUPP;
  3941. }
  3942. /* For split DSI, update the clock master first */
  3943. DSI_DEBUG("configuring seamless dynamic fps\n\n");
  3944. SDE_EVT32(SDE_EVTLOG_FUNC_ENTRY);
  3945. m_ctrl = &display->ctrl[display->clk_master_idx];
  3946. rc = dsi_ctrl_async_timing_update(m_ctrl->ctrl, timing);
  3947. if (rc) {
  3948. DSI_ERR("[%s] failed to dfps update host_%d, rc=%d\n",
  3949. display->name, i, rc);
  3950. goto error;
  3951. }
  3952. /* Update the rest of the controllers */
  3953. display_for_each_ctrl(i, display) {
  3954. ctrl = &display->ctrl[i];
  3955. if (!ctrl->ctrl || (ctrl == m_ctrl))
  3956. continue;
  3957. rc = dsi_ctrl_async_timing_update(ctrl->ctrl, timing);
  3958. if (rc) {
  3959. DSI_ERR("[%s] failed to dfps update host_%d, rc=%d\n",
  3960. display->name, i, rc);
  3961. goto error;
  3962. }
  3963. }
  3964. panel_mode = display->panel->cur_mode;
  3965. memcpy(panel_mode, dsi_mode, sizeof(*panel_mode));
  3966. /*
  3967. * dsi_mode_flags flags are used to communicate with other drm driver
  3968. * components, and are transient. They aren't inherently part of the
  3969. * display panel's mode and shouldn't be saved into the cached currently
  3970. * active mode.
  3971. */
  3972. panel_mode->dsi_mode_flags = 0;
  3973. error:
  3974. SDE_EVT32(SDE_EVTLOG_FUNC_EXIT);
  3975. return rc;
  3976. }
  3977. static int dsi_display_dfps_calc_front_porch(
  3978. u32 old_fps,
  3979. u32 new_fps,
  3980. u32 a_total,
  3981. u32 b_total,
  3982. u32 b_fp,
  3983. u32 *b_fp_out)
  3984. {
  3985. s32 b_fp_new;
  3986. int add_porches, diff;
  3987. if (!b_fp_out) {
  3988. DSI_ERR("Invalid params\n");
  3989. return -EINVAL;
  3990. }
  3991. if (!a_total || !new_fps) {
  3992. DSI_ERR("Invalid pixel total or new fps in mode request\n");
  3993. return -EINVAL;
  3994. }
  3995. /*
  3996. * Keep clock, other porches constant, use new fps, calc front porch
  3997. * new_vtotal = old_vtotal * (old_fps / new_fps )
  3998. * new_vfp - old_vfp = new_vtotal - old_vtotal
  3999. * new_vfp = old_vfp + old_vtotal * ((old_fps - new_fps)/ new_fps)
  4000. */
  4001. diff = abs(old_fps - new_fps);
  4002. add_porches = mult_frac(b_total, diff, new_fps);
  4003. if (old_fps > new_fps)
  4004. b_fp_new = b_fp + add_porches;
  4005. else
  4006. b_fp_new = b_fp - add_porches;
  4007. DSI_DEBUG("fps %u a %u b %u b_fp %u new_fp %d\n",
  4008. new_fps, a_total, b_total, b_fp, b_fp_new);
  4009. if (b_fp_new < 0) {
  4010. DSI_ERR("Invalid new_hfp calcluated%d\n", b_fp_new);
  4011. return -EINVAL;
  4012. }
  4013. /**
  4014. * TODO: To differentiate from clock method when communicating to the
  4015. * other components, perhaps we should set clk here to original value
  4016. */
  4017. *b_fp_out = b_fp_new;
  4018. return 0;
  4019. }
  4020. /**
  4021. * dsi_display_get_dfps_timing() - Get the new dfps values.
  4022. * @display: DSI display handle.
  4023. * @adj_mode: Mode value structure to be changed.
  4024. * It contains old timing values and latest fps value.
  4025. * New timing values are updated based on new fps.
  4026. * @curr_refresh_rate: Current fps rate.
  4027. * If zero , current fps rate is taken from
  4028. * display->panel->cur_mode.
  4029. * Return: error code.
  4030. */
  4031. static int dsi_display_get_dfps_timing(struct dsi_display *display,
  4032. struct dsi_display_mode *adj_mode,
  4033. u32 curr_refresh_rate)
  4034. {
  4035. struct dsi_dfps_capabilities dfps_caps;
  4036. struct dsi_display_mode per_ctrl_mode;
  4037. struct dsi_mode_info *timing;
  4038. struct dsi_ctrl *m_ctrl;
  4039. int rc = 0;
  4040. if (!display || !adj_mode) {
  4041. DSI_ERR("Invalid params\n");
  4042. return -EINVAL;
  4043. }
  4044. m_ctrl = display->ctrl[display->clk_master_idx].ctrl;
  4045. dsi_panel_get_dfps_caps(display->panel, &dfps_caps);
  4046. if (!dfps_caps.dfps_support) {
  4047. DSI_ERR("dfps not supported by panel\n");
  4048. return -EINVAL;
  4049. }
  4050. per_ctrl_mode = *adj_mode;
  4051. adjust_timing_by_ctrl_count(display, &per_ctrl_mode);
  4052. if (!curr_refresh_rate) {
  4053. if (!dsi_display_is_seamless_dfps_possible(display,
  4054. &per_ctrl_mode, dfps_caps.type)) {
  4055. DSI_ERR("seamless dynamic fps not supported for mode\n");
  4056. return -EINVAL;
  4057. }
  4058. if (display->panel->cur_mode) {
  4059. curr_refresh_rate =
  4060. display->panel->cur_mode->timing.refresh_rate;
  4061. } else {
  4062. DSI_ERR("cur_mode is not initialized\n");
  4063. return -EINVAL;
  4064. }
  4065. }
  4066. /* TODO: Remove this direct reference to the dsi_ctrl */
  4067. timing = &per_ctrl_mode.timing;
  4068. switch (dfps_caps.type) {
  4069. case DSI_DFPS_IMMEDIATE_VFP:
  4070. rc = dsi_display_dfps_calc_front_porch(
  4071. curr_refresh_rate,
  4072. timing->refresh_rate,
  4073. dsi_h_total_dce(timing),
  4074. DSI_V_TOTAL(timing),
  4075. timing->v_front_porch,
  4076. &adj_mode->timing.v_front_porch);
  4077. SDE_EVT32(SDE_EVTLOG_FUNC_CASE1, DSI_DFPS_IMMEDIATE_VFP,
  4078. curr_refresh_rate, timing->refresh_rate,
  4079. timing->v_front_porch, adj_mode->timing.v_front_porch);
  4080. break;
  4081. case DSI_DFPS_IMMEDIATE_HFP:
  4082. rc = dsi_display_dfps_calc_front_porch(
  4083. curr_refresh_rate,
  4084. timing->refresh_rate,
  4085. DSI_V_TOTAL(timing),
  4086. dsi_h_total_dce(timing),
  4087. timing->h_front_porch,
  4088. &adj_mode->timing.h_front_porch);
  4089. SDE_EVT32(SDE_EVTLOG_FUNC_CASE2, DSI_DFPS_IMMEDIATE_HFP,
  4090. curr_refresh_rate, timing->refresh_rate,
  4091. timing->h_front_porch, adj_mode->timing.h_front_porch);
  4092. if (!rc)
  4093. adj_mode->timing.h_front_porch *= display->ctrl_count;
  4094. break;
  4095. default:
  4096. DSI_ERR("Unsupported DFPS mode %d\n", dfps_caps.type);
  4097. rc = -ENOTSUPP;
  4098. }
  4099. return rc;
  4100. }
  4101. static bool dsi_display_validate_mode_seamless(struct dsi_display *display,
  4102. struct dsi_display_mode *adj_mode)
  4103. {
  4104. int rc = 0;
  4105. if (!display || !adj_mode) {
  4106. DSI_ERR("Invalid params\n");
  4107. return false;
  4108. }
  4109. /* Currently the only seamless transition is dynamic fps */
  4110. rc = dsi_display_get_dfps_timing(display, adj_mode, 0);
  4111. if (rc) {
  4112. DSI_DEBUG("Dynamic FPS not supported for seamless\n");
  4113. } else {
  4114. DSI_DEBUG("Mode switch is seamless Dynamic FPS\n");
  4115. adj_mode->dsi_mode_flags |= DSI_MODE_FLAG_DFPS |
  4116. DSI_MODE_FLAG_VBLANK_PRE_MODESET;
  4117. }
  4118. return rc;
  4119. }
  4120. static void dsi_display_validate_dms_fps(struct dsi_display_mode *cur_mode,
  4121. struct dsi_display_mode *to_mode)
  4122. {
  4123. u32 cur_fps, to_fps;
  4124. u32 cur_h_active, to_h_active;
  4125. u32 cur_v_active, to_v_active;
  4126. cur_fps = cur_mode->timing.refresh_rate;
  4127. to_fps = to_mode->timing.refresh_rate;
  4128. cur_h_active = cur_mode->timing.h_active;
  4129. cur_v_active = cur_mode->timing.v_active;
  4130. to_h_active = to_mode->timing.h_active;
  4131. to_v_active = to_mode->timing.v_active;
  4132. if ((cur_h_active == to_h_active) && (cur_v_active == to_v_active) &&
  4133. (cur_fps != to_fps)) {
  4134. to_mode->dsi_mode_flags |= DSI_MODE_FLAG_DMS_FPS;
  4135. DSI_DEBUG("DMS Modeset with FPS change\n");
  4136. } else {
  4137. to_mode->dsi_mode_flags &= ~DSI_MODE_FLAG_DMS_FPS;
  4138. }
  4139. }
  4140. static int dsi_display_set_mode_sub(struct dsi_display *display,
  4141. struct dsi_display_mode *mode,
  4142. u32 flags)
  4143. {
  4144. int rc = 0, clk_rate = 0;
  4145. int i;
  4146. struct dsi_display_ctrl *ctrl;
  4147. struct dsi_display_ctrl *mctrl;
  4148. struct dsi_display_mode_priv_info *priv_info;
  4149. bool commit_phy_timing = false;
  4150. struct dsi_dyn_clk_caps *dyn_clk_caps;
  4151. priv_info = mode->priv_info;
  4152. if (!priv_info) {
  4153. DSI_ERR("[%s] failed to get private info of the display mode\n",
  4154. display->name);
  4155. return -EINVAL;
  4156. }
  4157. SDE_EVT32(mode->dsi_mode_flags, mode->panel_mode);
  4158. display->panel->panel_mode = mode->panel_mode;
  4159. rc = dsi_panel_get_host_cfg_for_mode(display->panel,
  4160. mode,
  4161. &display->config);
  4162. if (rc) {
  4163. DSI_ERR("[%s] failed to get host config for mode, rc=%d\n",
  4164. display->name, rc);
  4165. goto error;
  4166. }
  4167. memcpy(&display->config.lane_map, &display->lane_map,
  4168. sizeof(display->lane_map));
  4169. mctrl = &display->ctrl[display->clk_master_idx];
  4170. dyn_clk_caps = &(display->panel->dyn_clk_caps);
  4171. if (mode->dsi_mode_flags &
  4172. (DSI_MODE_FLAG_DFPS | DSI_MODE_FLAG_VRR)) {
  4173. display_for_each_ctrl(i, display) {
  4174. ctrl = &display->ctrl[i];
  4175. if (!ctrl->ctrl || (ctrl != mctrl))
  4176. continue;
  4177. ctrl->ctrl->hw.ops.set_timing_db(&ctrl->ctrl->hw,
  4178. true);
  4179. dsi_phy_dynamic_refresh_clear(ctrl->phy);
  4180. if ((ctrl->ctrl->version >= DSI_CTRL_VERSION_2_5) &&
  4181. (dyn_clk_caps->maintain_const_fps)) {
  4182. dsi_phy_dynamic_refresh_trigger_sel(ctrl->phy,
  4183. true);
  4184. }
  4185. }
  4186. rc = dsi_display_dfps_update(display, mode);
  4187. if (rc) {
  4188. DSI_ERR("[%s]DSI dfps update failed, rc=%d\n",
  4189. display->name, rc);
  4190. goto error;
  4191. }
  4192. display_for_each_ctrl(i, display) {
  4193. ctrl = &display->ctrl[i];
  4194. rc = dsi_ctrl_update_host_config(ctrl->ctrl,
  4195. &display->config, mode, mode->dsi_mode_flags,
  4196. display->dsi_clk_handle);
  4197. if (rc) {
  4198. DSI_ERR("failed to update ctrl config\n");
  4199. goto error;
  4200. }
  4201. }
  4202. if (priv_info->phy_timing_len) {
  4203. display_for_each_ctrl(i, display) {
  4204. ctrl = &display->ctrl[i];
  4205. rc = dsi_phy_set_timing_params(ctrl->phy,
  4206. priv_info->phy_timing_val,
  4207. priv_info->phy_timing_len,
  4208. commit_phy_timing);
  4209. if (rc)
  4210. DSI_ERR("Fail to add timing params\n");
  4211. }
  4212. }
  4213. if (!(mode->dsi_mode_flags & DSI_MODE_FLAG_DYN_CLK))
  4214. return rc;
  4215. }
  4216. if (mode->dsi_mode_flags & DSI_MODE_FLAG_DYN_CLK) {
  4217. if (display->panel->panel_mode == DSI_OP_VIDEO_MODE) {
  4218. rc = dsi_display_dynamic_clk_switch_vid(display, mode);
  4219. if (rc)
  4220. DSI_ERR("dynamic clk change failed %d\n", rc);
  4221. /*
  4222. * skip rest of the opearations since
  4223. * dsi_display_dynamic_clk_switch_vid() already takes
  4224. * care of them.
  4225. */
  4226. return rc;
  4227. } else if (display->panel->panel_mode == DSI_OP_CMD_MODE) {
  4228. clk_rate = mode->timing.clk_rate_hz;
  4229. rc = dsi_display_dynamic_clk_configure_cmd(display,
  4230. clk_rate);
  4231. if (rc) {
  4232. DSI_ERR("Failed to configure dynamic clk\n");
  4233. return rc;
  4234. }
  4235. }
  4236. }
  4237. display_for_each_ctrl(i, display) {
  4238. ctrl = &display->ctrl[i];
  4239. rc = dsi_ctrl_update_host_config(ctrl->ctrl, &display->config,
  4240. mode, mode->dsi_mode_flags,
  4241. display->dsi_clk_handle);
  4242. if (rc) {
  4243. DSI_ERR("[%s] failed to update ctrl config, rc=%d\n",
  4244. display->name, rc);
  4245. goto error;
  4246. }
  4247. }
  4248. if ((mode->dsi_mode_flags & DSI_MODE_FLAG_DMS) &&
  4249. (display->panel->panel_mode == DSI_OP_CMD_MODE)) {
  4250. u64 cur_bitclk = display->panel->cur_mode->timing.clk_rate_hz;
  4251. u64 to_bitclk = mode->timing.clk_rate_hz;
  4252. commit_phy_timing = true;
  4253. /* No need to set clkrate pending flag if clocks are same */
  4254. if ((!cur_bitclk && !to_bitclk) || (cur_bitclk != to_bitclk))
  4255. atomic_set(&display->clkrate_change_pending, 1);
  4256. dsi_display_validate_dms_fps(display->panel->cur_mode, mode);
  4257. }
  4258. if (priv_info->phy_timing_len) {
  4259. display_for_each_ctrl(i, display) {
  4260. ctrl = &display->ctrl[i];
  4261. rc = dsi_phy_set_timing_params(ctrl->phy,
  4262. priv_info->phy_timing_val,
  4263. priv_info->phy_timing_len,
  4264. commit_phy_timing);
  4265. if (rc)
  4266. DSI_ERR("failed to add DSI PHY timing params\n");
  4267. }
  4268. }
  4269. error:
  4270. return rc;
  4271. }
  4272. /**
  4273. * _dsi_display_dev_init - initializes the display device
  4274. * Initialization will acquire references to the resources required for the
  4275. * display hardware to function.
  4276. * @display: Handle to the display
  4277. * Returns: Zero on success
  4278. */
  4279. static int _dsi_display_dev_init(struct dsi_display *display)
  4280. {
  4281. int rc = 0;
  4282. if (!display) {
  4283. DSI_ERR("invalid display\n");
  4284. return -EINVAL;
  4285. }
  4286. if (!display->panel_node)
  4287. return 0;
  4288. mutex_lock(&display->display_lock);
  4289. display->parser = dsi_parser_get(&display->pdev->dev);
  4290. if (display->fw && display->parser)
  4291. display->parser_node = dsi_parser_get_head_node(
  4292. display->parser, display->fw->data,
  4293. display->fw->size);
  4294. rc = dsi_display_parse_dt(display);
  4295. if (rc) {
  4296. DSI_ERR("[%s] failed to parse dt, rc=%d\n", display->name, rc);
  4297. goto error;
  4298. }
  4299. rc = dsi_display_res_init(display);
  4300. if (rc) {
  4301. DSI_ERR("[%s] failed to initialize resources, rc=%d\n",
  4302. display->name, rc);
  4303. goto error;
  4304. }
  4305. error:
  4306. mutex_unlock(&display->display_lock);
  4307. return rc;
  4308. }
  4309. /**
  4310. * _dsi_display_dev_deinit - deinitializes the display device
  4311. * All the resources acquired during device init will be released.
  4312. * @display: Handle to the display
  4313. * Returns: Zero on success
  4314. */
  4315. static int _dsi_display_dev_deinit(struct dsi_display *display)
  4316. {
  4317. int rc = 0;
  4318. if (!display) {
  4319. DSI_ERR("invalid display\n");
  4320. return -EINVAL;
  4321. }
  4322. mutex_lock(&display->display_lock);
  4323. rc = dsi_display_res_deinit(display);
  4324. if (rc)
  4325. DSI_ERR("[%s] failed to deinitialize resource, rc=%d\n",
  4326. display->name, rc);
  4327. mutex_unlock(&display->display_lock);
  4328. return rc;
  4329. }
  4330. /**
  4331. * dsi_display_cont_splash_res_disable() - Disable resource votes added in probe
  4332. * @dsi_display: Pointer to dsi display
  4333. * Returns: Zero on success
  4334. */
  4335. int dsi_display_cont_splash_res_disable(void *dsi_display)
  4336. {
  4337. struct dsi_display *display = dsi_display;
  4338. int rc = 0;
  4339. /* Remove the panel vote that was added during dsi display probe */
  4340. rc = dsi_pwr_enable_regulator(&display->panel->power_info, false);
  4341. if (rc)
  4342. DSI_ERR("[%s] failed to disable vregs, rc=%d\n",
  4343. display->panel->name, rc);
  4344. return rc;
  4345. }
  4346. /**
  4347. * dsi_display_cont_splash_config() - Initialize resources for continuous splash
  4348. * @dsi_display: Pointer to dsi display
  4349. * Returns: Zero on success
  4350. */
  4351. int dsi_display_cont_splash_config(void *dsi_display)
  4352. {
  4353. struct dsi_display *display = dsi_display;
  4354. int rc = 0;
  4355. /* Vote for gdsc required to read register address space */
  4356. if (!display) {
  4357. DSI_ERR("invalid input display param\n");
  4358. return -EINVAL;
  4359. }
  4360. rc = pm_runtime_get_sync(display->drm_dev->dev);
  4361. if (rc < 0) {
  4362. DSI_ERR("failed to vote gdsc for continuous splash, rc=%d\n",
  4363. rc);
  4364. return rc;
  4365. }
  4366. mutex_lock(&display->display_lock);
  4367. display->is_cont_splash_enabled = true;
  4368. /* Update splash status for clock manager */
  4369. dsi_display_clk_mngr_update_splash_status(display->clk_mngr,
  4370. display->is_cont_splash_enabled);
  4371. SDE_EVT32(SDE_EVTLOG_FUNC_ENTRY, display->is_cont_splash_enabled);
  4372. /* Set up ctrl isr before enabling core clk */
  4373. dsi_display_ctrl_isr_configure(display, true);
  4374. /* Vote for Core clk and link clk. Votes on ctrl and phy
  4375. * regulator are inplicit from pre clk on callback
  4376. */
  4377. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  4378. DSI_ALL_CLKS, DSI_CLK_ON);
  4379. if (rc) {
  4380. DSI_ERR("[%s] failed to enable DSI link clocks, rc=%d\n",
  4381. display->name, rc);
  4382. goto clk_manager_update;
  4383. }
  4384. mutex_unlock(&display->display_lock);
  4385. /* Set the current brightness level */
  4386. dsi_panel_bl_handoff(display->panel);
  4387. return rc;
  4388. clk_manager_update:
  4389. dsi_display_ctrl_isr_configure(display, false);
  4390. /* Update splash status for clock manager */
  4391. dsi_display_clk_mngr_update_splash_status(display->clk_mngr,
  4392. false);
  4393. pm_runtime_put_sync(display->drm_dev->dev);
  4394. display->is_cont_splash_enabled = false;
  4395. mutex_unlock(&display->display_lock);
  4396. return rc;
  4397. }
  4398. /**
  4399. * dsi_display_splash_res_cleanup() - cleanup for continuous splash
  4400. * @display: Pointer to dsi display
  4401. * Returns: Zero on success
  4402. */
  4403. int dsi_display_splash_res_cleanup(struct dsi_display *display)
  4404. {
  4405. int rc = 0;
  4406. if (!display->is_cont_splash_enabled)
  4407. return 0;
  4408. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  4409. DSI_ALL_CLKS, DSI_CLK_OFF);
  4410. if (rc)
  4411. DSI_ERR("[%s] failed to disable DSI link clocks, rc=%d\n",
  4412. display->name, rc);
  4413. pm_runtime_put_sync(display->drm_dev->dev);
  4414. display->is_cont_splash_enabled = false;
  4415. /* Update splash status for clock manager */
  4416. dsi_display_clk_mngr_update_splash_status(display->clk_mngr,
  4417. display->is_cont_splash_enabled);
  4418. SDE_EVT32(SDE_EVTLOG_FUNC_EXIT, display->is_cont_splash_enabled);
  4419. return rc;
  4420. }
  4421. static int dsi_display_force_update_dsi_clk(struct dsi_display *display)
  4422. {
  4423. int rc = 0;
  4424. rc = dsi_display_link_clk_force_update_ctrl(display->dsi_clk_handle);
  4425. if (!rc) {
  4426. DSI_INFO("dsi bit clk has been configured to %d\n",
  4427. display->cached_clk_rate);
  4428. atomic_set(&display->clkrate_change_pending, 0);
  4429. } else {
  4430. DSI_ERR("Failed to configure dsi bit clock '%d'. rc = %d\n",
  4431. display->cached_clk_rate, rc);
  4432. }
  4433. return rc;
  4434. }
  4435. static int dsi_display_validate_split_link(struct dsi_display *display)
  4436. {
  4437. int i, rc = 0;
  4438. struct dsi_display_ctrl *ctrl;
  4439. struct dsi_host_common_cfg *host = &display->panel->host_config;
  4440. if (!host->split_link.split_link_enabled)
  4441. return 0;
  4442. if (display->panel->panel_mode == DSI_OP_CMD_MODE) {
  4443. DSI_ERR("[%s] split link is not supported in command mode\n",
  4444. display->name);
  4445. rc = -ENOTSUPP;
  4446. goto error;
  4447. }
  4448. display_for_each_ctrl(i, display) {
  4449. ctrl = &display->ctrl[i];
  4450. if (!ctrl->ctrl->split_link_supported) {
  4451. DSI_ERR("[%s] split link is not supported by hw\n",
  4452. display->name);
  4453. rc = -ENOTSUPP;
  4454. goto error;
  4455. }
  4456. set_bit(DSI_PHY_SPLIT_LINK, ctrl->phy->hw.feature_map);
  4457. }
  4458. DSI_DEBUG("Split link is enabled\n");
  4459. return 0;
  4460. error:
  4461. host->split_link.split_link_enabled = false;
  4462. return rc;
  4463. }
  4464. static int dsi_display_get_io_resources(struct msm_io_res *io_res, void *data)
  4465. {
  4466. int rc = 0;
  4467. struct dsi_display *display;
  4468. if (!data)
  4469. return -EINVAL;
  4470. rc = dsi_ctrl_get_io_resources(io_res);
  4471. if (rc)
  4472. goto end;
  4473. rc = dsi_phy_get_io_resources(io_res);
  4474. if (rc)
  4475. goto end;
  4476. display = (struct dsi_display *)data;
  4477. rc = dsi_panel_get_io_resources(display->panel, io_res);
  4478. end:
  4479. return rc;
  4480. }
  4481. static int dsi_display_pre_release(void *data)
  4482. {
  4483. if (!data)
  4484. return -EINVAL;
  4485. dsi_display_ctrl_irq_update((struct dsi_display *)data, false);
  4486. return 0;
  4487. }
  4488. static int dsi_display_pre_acquire(void *data)
  4489. {
  4490. if (!data)
  4491. return -EINVAL;
  4492. dsi_display_ctrl_irq_update((struct dsi_display *)data, true);
  4493. return 0;
  4494. }
  4495. /**
  4496. * dsi_display_bind - bind dsi device with controlling device
  4497. * @dev: Pointer to base of platform device
  4498. * @master: Pointer to container of drm device
  4499. * @data: Pointer to private data
  4500. * Returns: Zero on success
  4501. */
  4502. static int dsi_display_bind(struct device *dev,
  4503. struct device *master,
  4504. void *data)
  4505. {
  4506. struct dsi_display_ctrl *display_ctrl;
  4507. struct drm_device *drm;
  4508. struct dsi_display *display;
  4509. struct dsi_clk_info info;
  4510. struct clk_ctrl_cb clk_cb;
  4511. void *handle = NULL;
  4512. struct platform_device *pdev = to_platform_device(dev);
  4513. char *client1 = "dsi_clk_client";
  4514. char *client2 = "mdp_event_client";
  4515. struct msm_vm_ops vm_event_ops = {
  4516. .vm_get_io_resources = dsi_display_get_io_resources,
  4517. .vm_pre_hw_release = dsi_display_pre_release,
  4518. .vm_post_hw_acquire = dsi_display_pre_acquire,
  4519. };
  4520. int i, rc = 0;
  4521. if (!dev || !pdev || !master) {
  4522. DSI_ERR("invalid param(s), dev %pK, pdev %pK, master %pK\n",
  4523. dev, pdev, master);
  4524. return -EINVAL;
  4525. }
  4526. drm = dev_get_drvdata(master);
  4527. display = platform_get_drvdata(pdev);
  4528. if (!drm || !display) {
  4529. DSI_ERR("invalid param(s), drm %pK, display %pK\n",
  4530. drm, display);
  4531. return -EINVAL;
  4532. }
  4533. if (!display->panel_node)
  4534. return 0;
  4535. if (!display->fw)
  4536. display->name = display->panel_node->name;
  4537. /* defer bind if ext bridge driver is not loaded */
  4538. if (display->panel && display->panel->host_config.ext_bridge_mode) {
  4539. for (i = 0; i < display->ext_bridge_cnt; i++) {
  4540. if (!of_drm_find_bridge(
  4541. display->ext_bridge[i].node_of)) {
  4542. DSI_DEBUG("defer for bridge[%d] %s\n", i,
  4543. display->ext_bridge[i].node_of->full_name);
  4544. return -EPROBE_DEFER;
  4545. }
  4546. }
  4547. }
  4548. mutex_lock(&display->display_lock);
  4549. rc = dsi_display_validate_split_link(display);
  4550. if (rc) {
  4551. DSI_ERR("[%s] split link validation failed, rc=%d\n",
  4552. display->name, rc);
  4553. goto error;
  4554. }
  4555. rc = dsi_display_debugfs_init(display);
  4556. if (rc) {
  4557. DSI_ERR("[%s] debugfs init failed, rc=%d\n", display->name, rc);
  4558. goto error;
  4559. }
  4560. atomic_set(&display->clkrate_change_pending, 0);
  4561. display->cached_clk_rate = 0;
  4562. memset(&info, 0x0, sizeof(info));
  4563. display_for_each_ctrl(i, display) {
  4564. display_ctrl = &display->ctrl[i];
  4565. rc = dsi_ctrl_drv_init(display_ctrl->ctrl, display->root);
  4566. if (rc) {
  4567. DSI_ERR("[%s] failed to initialize ctrl[%d], rc=%d\n",
  4568. display->name, i, rc);
  4569. goto error_ctrl_deinit;
  4570. }
  4571. display_ctrl->ctrl->horiz_index = i;
  4572. rc = dsi_phy_drv_init(display_ctrl->phy);
  4573. if (rc) {
  4574. DSI_ERR("[%s] Failed to initialize phy[%d], rc=%d\n",
  4575. display->name, i, rc);
  4576. (void)dsi_ctrl_drv_deinit(display_ctrl->ctrl);
  4577. goto error_ctrl_deinit;
  4578. }
  4579. display_ctrl->ctrl->dma_cmd_workq = display->dma_cmd_workq;
  4580. memcpy(&info.c_clks[i],
  4581. (&display_ctrl->ctrl->clk_info.core_clks),
  4582. sizeof(struct dsi_core_clk_info));
  4583. memcpy(&info.l_hs_clks[i],
  4584. (&display_ctrl->ctrl->clk_info.hs_link_clks),
  4585. sizeof(struct dsi_link_hs_clk_info));
  4586. memcpy(&info.l_lp_clks[i],
  4587. (&display_ctrl->ctrl->clk_info.lp_link_clks),
  4588. sizeof(struct dsi_link_lp_clk_info));
  4589. info.c_clks[i].drm = drm;
  4590. info.ctrl_index[i] = display_ctrl->ctrl->cell_index;
  4591. }
  4592. info.pre_clkoff_cb = dsi_pre_clkoff_cb;
  4593. info.pre_clkon_cb = dsi_pre_clkon_cb;
  4594. info.post_clkoff_cb = dsi_post_clkoff_cb;
  4595. info.post_clkon_cb = dsi_post_clkon_cb;
  4596. info.priv_data = display;
  4597. info.master_ndx = display->clk_master_idx;
  4598. info.dsi_ctrl_count = display->ctrl_count;
  4599. snprintf(info.name, MAX_STRING_LEN,
  4600. "DSI_MNGR-%s", display->name);
  4601. display->clk_mngr = dsi_display_clk_mngr_register(&info);
  4602. if (IS_ERR_OR_NULL(display->clk_mngr)) {
  4603. rc = PTR_ERR(display->clk_mngr);
  4604. display->clk_mngr = NULL;
  4605. DSI_ERR("dsi clock registration failed, rc = %d\n", rc);
  4606. goto error_ctrl_deinit;
  4607. }
  4608. handle = dsi_register_clk_handle(display->clk_mngr, client1);
  4609. if (IS_ERR_OR_NULL(handle)) {
  4610. rc = PTR_ERR(handle);
  4611. DSI_ERR("failed to register %s client, rc = %d\n",
  4612. client1, rc);
  4613. goto error_clk_deinit;
  4614. } else {
  4615. display->dsi_clk_handle = handle;
  4616. }
  4617. handle = dsi_register_clk_handle(display->clk_mngr, client2);
  4618. if (IS_ERR_OR_NULL(handle)) {
  4619. rc = PTR_ERR(handle);
  4620. DSI_ERR("failed to register %s client, rc = %d\n",
  4621. client2, rc);
  4622. goto error_clk_client_deinit;
  4623. } else {
  4624. display->mdp_clk_handle = handle;
  4625. }
  4626. clk_cb.priv = display;
  4627. clk_cb.dsi_clk_cb = dsi_display_clk_ctrl_cb;
  4628. display_for_each_ctrl(i, display) {
  4629. display_ctrl = &display->ctrl[i];
  4630. rc = dsi_ctrl_clk_cb_register(display_ctrl->ctrl, &clk_cb);
  4631. if (rc) {
  4632. DSI_ERR("[%s] failed to register ctrl clk_cb[%d], rc=%d\n",
  4633. display->name, i, rc);
  4634. goto error_ctrl_deinit;
  4635. }
  4636. rc = dsi_phy_clk_cb_register(display_ctrl->phy, &clk_cb);
  4637. if (rc) {
  4638. DSI_ERR("[%s] failed to register phy clk_cb[%d], rc=%d\n",
  4639. display->name, i, rc);
  4640. goto error_ctrl_deinit;
  4641. }
  4642. }
  4643. dsi_display_update_byte_intf_div(display);
  4644. rc = dsi_display_mipi_host_init(display);
  4645. if (rc) {
  4646. DSI_ERR("[%s] failed to initialize mipi host, rc=%d\n",
  4647. display->name, rc);
  4648. goto error_ctrl_deinit;
  4649. }
  4650. rc = dsi_panel_drv_init(display->panel, &display->host);
  4651. if (rc) {
  4652. if (rc != -EPROBE_DEFER)
  4653. DSI_ERR("[%s] failed to initialize panel driver, rc=%d\n",
  4654. display->name, rc);
  4655. goto error_host_deinit;
  4656. }
  4657. DSI_INFO("Successfully bind display panel '%s'\n", display->name);
  4658. display->drm_dev = drm;
  4659. display_for_each_ctrl(i, display) {
  4660. display_ctrl = &display->ctrl[i];
  4661. if (!display_ctrl->phy || !display_ctrl->ctrl)
  4662. continue;
  4663. display_ctrl->ctrl->drm_dev = drm;
  4664. rc = dsi_phy_set_clk_freq(display_ctrl->phy,
  4665. &display_ctrl->ctrl->clk_freq);
  4666. if (rc) {
  4667. DSI_ERR("[%s] failed to set phy clk freq, rc=%d\n",
  4668. display->name, rc);
  4669. goto error;
  4670. }
  4671. }
  4672. /* register te irq handler */
  4673. dsi_display_register_te_irq(display);
  4674. msm_register_vm_event(master, dev, &vm_event_ops, (void *)display);
  4675. goto error;
  4676. error_host_deinit:
  4677. (void)dsi_display_mipi_host_deinit(display);
  4678. error_clk_client_deinit:
  4679. (void)dsi_deregister_clk_handle(display->dsi_clk_handle);
  4680. error_clk_deinit:
  4681. (void)dsi_display_clk_mngr_deregister(display->clk_mngr);
  4682. error_ctrl_deinit:
  4683. for (i = i - 1; i >= 0; i--) {
  4684. display_ctrl = &display->ctrl[i];
  4685. (void)dsi_phy_drv_deinit(display_ctrl->phy);
  4686. (void)dsi_ctrl_drv_deinit(display_ctrl->ctrl);
  4687. }
  4688. (void)dsi_display_debugfs_deinit(display);
  4689. error:
  4690. mutex_unlock(&display->display_lock);
  4691. return rc;
  4692. }
  4693. /**
  4694. * dsi_display_unbind - unbind dsi from controlling device
  4695. * @dev: Pointer to base of platform device
  4696. * @master: Pointer to container of drm device
  4697. * @data: Pointer to private data
  4698. */
  4699. static void dsi_display_unbind(struct device *dev,
  4700. struct device *master, void *data)
  4701. {
  4702. struct dsi_display_ctrl *display_ctrl;
  4703. struct dsi_display *display;
  4704. struct platform_device *pdev = to_platform_device(dev);
  4705. int i, rc = 0;
  4706. if (!dev || !pdev || !master) {
  4707. DSI_ERR("invalid param(s)\n");
  4708. return;
  4709. }
  4710. display = platform_get_drvdata(pdev);
  4711. if (!display || !display->panel_node) {
  4712. DSI_ERR("invalid display\n");
  4713. return;
  4714. }
  4715. mutex_lock(&display->display_lock);
  4716. rc = dsi_display_mipi_host_deinit(display);
  4717. if (rc)
  4718. DSI_ERR("[%s] failed to deinit mipi hosts, rc=%d\n",
  4719. display->name,
  4720. rc);
  4721. display_for_each_ctrl(i, display) {
  4722. display_ctrl = &display->ctrl[i];
  4723. rc = dsi_phy_drv_deinit(display_ctrl->phy);
  4724. if (rc)
  4725. DSI_ERR("[%s] failed to deinit phy%d driver, rc=%d\n",
  4726. display->name, i, rc);
  4727. display->ctrl->ctrl->dma_cmd_workq = NULL;
  4728. rc = dsi_ctrl_drv_deinit(display_ctrl->ctrl);
  4729. if (rc)
  4730. DSI_ERR("[%s] failed to deinit ctrl%d driver, rc=%d\n",
  4731. display->name, i, rc);
  4732. }
  4733. atomic_set(&display->clkrate_change_pending, 0);
  4734. (void)dsi_display_debugfs_deinit(display);
  4735. mutex_unlock(&display->display_lock);
  4736. }
  4737. static const struct component_ops dsi_display_comp_ops = {
  4738. .bind = dsi_display_bind,
  4739. .unbind = dsi_display_unbind,
  4740. };
  4741. static struct platform_driver dsi_display_driver = {
  4742. .probe = dsi_display_dev_probe,
  4743. .remove = dsi_display_dev_remove,
  4744. .driver = {
  4745. .name = "msm-dsi-display",
  4746. .of_match_table = dsi_display_dt_match,
  4747. .suppress_bind_attrs = true,
  4748. },
  4749. };
  4750. static int dsi_display_init(struct dsi_display *display)
  4751. {
  4752. int rc = 0;
  4753. struct platform_device *pdev = display->pdev;
  4754. mutex_init(&display->display_lock);
  4755. rc = _dsi_display_dev_init(display);
  4756. if (rc) {
  4757. DSI_ERR("device init failed, rc=%d\n", rc);
  4758. goto end;
  4759. }
  4760. /*
  4761. * Vote on panel regulator is added to make sure panel regulators
  4762. * are ON for cont-splash enabled usecase.
  4763. * This panel regulator vote will be removed only in:
  4764. * 1) device suspend when cont-splash is enabled.
  4765. * 2) cont_splash_res_disable() when cont-splash is disabled.
  4766. * For GKI, adding this vote will make sure that sync_state
  4767. * kernel driver doesn't disable the panel regulators after
  4768. * dsi probe is complete.
  4769. */
  4770. if (display->panel) {
  4771. rc = dsi_pwr_enable_regulator(&display->panel->power_info,
  4772. true);
  4773. if (rc) {
  4774. DSI_ERR("[%s] failed to enable vregs, rc=%d\n",
  4775. display->panel->name, rc);
  4776. return rc;
  4777. }
  4778. }
  4779. rc = component_add(&pdev->dev, &dsi_display_comp_ops);
  4780. if (rc)
  4781. DSI_ERR("component add failed, rc=%d\n", rc);
  4782. DSI_DEBUG("component add success: %s\n", display->name);
  4783. end:
  4784. return rc;
  4785. }
  4786. static void dsi_display_firmware_display(const struct firmware *fw,
  4787. void *context)
  4788. {
  4789. struct dsi_display *display = context;
  4790. if (fw) {
  4791. DSI_INFO("reading data from firmware, size=%zd\n",
  4792. fw->size);
  4793. display->fw = fw;
  4794. display->name = "dsi_firmware_display";
  4795. } else {
  4796. DSI_INFO("no firmware available, fallback to device node\n");
  4797. }
  4798. if (dsi_display_init(display))
  4799. return;
  4800. DSI_DEBUG("success\n");
  4801. }
  4802. int dsi_display_dev_probe(struct platform_device *pdev)
  4803. {
  4804. struct dsi_display *display = NULL;
  4805. struct device_node *node = NULL, *panel_node = NULL, *mdp_node = NULL;
  4806. int rc = 0, index = DSI_PRIMARY;
  4807. bool firm_req = false;
  4808. struct dsi_display_boot_param *boot_disp;
  4809. if (!pdev || !pdev->dev.of_node) {
  4810. DSI_ERR("pdev not found\n");
  4811. rc = -ENODEV;
  4812. goto end;
  4813. }
  4814. display = devm_kzalloc(&pdev->dev, sizeof(*display), GFP_KERNEL);
  4815. if (!display) {
  4816. rc = -ENOMEM;
  4817. goto end;
  4818. }
  4819. display->dma_cmd_workq = create_singlethread_workqueue(
  4820. "dsi_dma_cmd_workq");
  4821. if (!display->dma_cmd_workq) {
  4822. DSI_ERR("failed to create work queue\n");
  4823. rc = -EINVAL;
  4824. goto end;
  4825. }
  4826. mdp_node = of_parse_phandle(pdev->dev.of_node, "qcom,mdp", 0);
  4827. if (!mdp_node) {
  4828. DSI_ERR("mdp_node not found\n");
  4829. rc = -ENODEV;
  4830. goto end;
  4831. }
  4832. display->trusted_vm_env = of_property_read_bool(mdp_node,
  4833. "qcom,sde-trusted-vm-env");
  4834. if (display->trusted_vm_env)
  4835. DSI_INFO("Display enabled with trusted vm path\n");
  4836. /* initialize panel id to UINT64_MAX */
  4837. display->panel_id = ~0x0;
  4838. display->display_type = of_get_property(pdev->dev.of_node,
  4839. "label", NULL);
  4840. if (!display->display_type)
  4841. display->display_type = "primary";
  4842. if (!strcmp(display->display_type, "secondary"))
  4843. index = DSI_SECONDARY;
  4844. boot_disp = &boot_displays[index];
  4845. node = pdev->dev.of_node;
  4846. if (boot_disp->boot_disp_en) {
  4847. /* The panel name should be same as UEFI name index */
  4848. panel_node = of_find_node_by_name(mdp_node, boot_disp->name);
  4849. if (!panel_node)
  4850. DSI_WARN("panel_node %s not found\n", boot_disp->name);
  4851. } else {
  4852. panel_node = of_parse_phandle(node,
  4853. "qcom,dsi-default-panel", 0);
  4854. if (!panel_node)
  4855. DSI_WARN("default panel not found\n");
  4856. }
  4857. boot_disp->node = pdev->dev.of_node;
  4858. boot_disp->disp = display;
  4859. display->panel_node = panel_node;
  4860. display->pdev = pdev;
  4861. display->boot_disp = boot_disp;
  4862. dsi_display_parse_cmdline_topology(display, index);
  4863. platform_set_drvdata(pdev, display);
  4864. /* initialize display in firmware callback */
  4865. if (!boot_disp->boot_disp_en &&
  4866. IS_ENABLED(CONFIG_DSI_PARSER) &&
  4867. !display->trusted_vm_env) {
  4868. firm_req = !request_firmware_nowait(
  4869. THIS_MODULE, 1, "dsi_prop",
  4870. &pdev->dev, GFP_KERNEL, display,
  4871. dsi_display_firmware_display);
  4872. }
  4873. if (!firm_req) {
  4874. rc = dsi_display_init(display);
  4875. if (rc)
  4876. goto end;
  4877. }
  4878. return 0;
  4879. end:
  4880. if (display)
  4881. devm_kfree(&pdev->dev, display);
  4882. return rc;
  4883. }
  4884. int dsi_display_dev_remove(struct platform_device *pdev)
  4885. {
  4886. int rc = 0, i = 0;
  4887. struct dsi_display *display;
  4888. struct dsi_display_ctrl *ctrl;
  4889. if (!pdev) {
  4890. DSI_ERR("Invalid device\n");
  4891. return -EINVAL;
  4892. }
  4893. display = platform_get_drvdata(pdev);
  4894. /* decrement ref count */
  4895. of_node_put(display->panel_node);
  4896. if (display->dma_cmd_workq) {
  4897. flush_workqueue(display->dma_cmd_workq);
  4898. destroy_workqueue(display->dma_cmd_workq);
  4899. display->dma_cmd_workq = NULL;
  4900. display_for_each_ctrl(i, display) {
  4901. ctrl = &display->ctrl[i];
  4902. if (!ctrl->ctrl)
  4903. continue;
  4904. ctrl->ctrl->dma_cmd_workq = NULL;
  4905. }
  4906. }
  4907. (void)_dsi_display_dev_deinit(display);
  4908. platform_set_drvdata(pdev, NULL);
  4909. devm_kfree(&pdev->dev, display);
  4910. return rc;
  4911. }
  4912. int dsi_display_get_num_of_displays(void)
  4913. {
  4914. int i, count = 0;
  4915. for (i = 0; i < MAX_DSI_ACTIVE_DISPLAY; i++) {
  4916. struct dsi_display *display = boot_displays[i].disp;
  4917. if (display && display->panel_node)
  4918. count++;
  4919. }
  4920. return count;
  4921. }
  4922. int dsi_display_get_active_displays(void **display_array, u32 max_display_count)
  4923. {
  4924. int index = 0, count = 0;
  4925. if (!display_array || !max_display_count) {
  4926. DSI_ERR("invalid params\n");
  4927. return 0;
  4928. }
  4929. for (index = 0; index < MAX_DSI_ACTIVE_DISPLAY; index++) {
  4930. struct dsi_display *display = boot_displays[index].disp;
  4931. if (display && display->panel_node)
  4932. display_array[count++] = display;
  4933. }
  4934. return count;
  4935. }
  4936. void dsi_display_set_active_state(struct dsi_display *display, bool is_active)
  4937. {
  4938. if (!display)
  4939. return;
  4940. mutex_lock(&display->display_lock);
  4941. display->is_active = is_active;
  4942. mutex_unlock(&display->display_lock);
  4943. }
  4944. int dsi_display_drm_bridge_init(struct dsi_display *display,
  4945. struct drm_encoder *enc)
  4946. {
  4947. int rc = 0;
  4948. struct dsi_bridge *bridge;
  4949. struct msm_drm_private *priv = NULL;
  4950. if (!display || !display->drm_dev || !enc) {
  4951. DSI_ERR("invalid param(s)\n");
  4952. return -EINVAL;
  4953. }
  4954. mutex_lock(&display->display_lock);
  4955. priv = display->drm_dev->dev_private;
  4956. if (!priv) {
  4957. DSI_ERR("Private data is not present\n");
  4958. rc = -EINVAL;
  4959. goto error;
  4960. }
  4961. if (display->bridge) {
  4962. DSI_ERR("display is already initialize\n");
  4963. goto error;
  4964. }
  4965. bridge = dsi_drm_bridge_init(display, display->drm_dev, enc);
  4966. if (IS_ERR_OR_NULL(bridge)) {
  4967. rc = PTR_ERR(bridge);
  4968. DSI_ERR("[%s] brige init failed, %d\n", display->name, rc);
  4969. goto error;
  4970. }
  4971. display->bridge = bridge;
  4972. priv->bridges[priv->num_bridges++] = &bridge->base;
  4973. error:
  4974. mutex_unlock(&display->display_lock);
  4975. return rc;
  4976. }
  4977. int dsi_display_drm_bridge_deinit(struct dsi_display *display)
  4978. {
  4979. int rc = 0;
  4980. if (!display) {
  4981. DSI_ERR("Invalid params\n");
  4982. return -EINVAL;
  4983. }
  4984. mutex_lock(&display->display_lock);
  4985. dsi_drm_bridge_cleanup(display->bridge);
  4986. display->bridge = NULL;
  4987. mutex_unlock(&display->display_lock);
  4988. return rc;
  4989. }
  4990. /* Hook functions to call external connector, pointer validation is
  4991. * done in dsi_display_drm_ext_bridge_init.
  4992. */
  4993. static enum drm_connector_status dsi_display_drm_ext_detect(
  4994. struct drm_connector *connector,
  4995. bool force,
  4996. void *disp)
  4997. {
  4998. struct dsi_display *display = disp;
  4999. return display->ext_conn->funcs->detect(display->ext_conn, force);
  5000. }
  5001. static int dsi_display_drm_ext_get_modes(
  5002. struct drm_connector *connector, void *disp,
  5003. const struct msm_resource_caps_info *avail_res)
  5004. {
  5005. struct dsi_display *display = disp;
  5006. struct drm_display_mode *pmode, *pt;
  5007. int count;
  5008. /* if there are modes defined in panel, ignore external modes */
  5009. if (display->panel->num_timing_nodes)
  5010. return dsi_connector_get_modes(connector, disp, avail_res);
  5011. count = display->ext_conn->helper_private->get_modes(
  5012. display->ext_conn);
  5013. list_for_each_entry_safe(pmode, pt,
  5014. &display->ext_conn->probed_modes, head) {
  5015. list_move_tail(&pmode->head, &connector->probed_modes);
  5016. }
  5017. connector->display_info = display->ext_conn->display_info;
  5018. return count;
  5019. }
  5020. static enum drm_mode_status dsi_display_drm_ext_mode_valid(
  5021. struct drm_connector *connector,
  5022. struct drm_display_mode *mode,
  5023. void *disp, const struct msm_resource_caps_info *avail_res)
  5024. {
  5025. struct dsi_display *display = disp;
  5026. enum drm_mode_status status;
  5027. /* always do internal mode_valid check */
  5028. status = dsi_conn_mode_valid(connector, mode, disp, avail_res);
  5029. if (status != MODE_OK)
  5030. return status;
  5031. return display->ext_conn->helper_private->mode_valid(
  5032. display->ext_conn, mode);
  5033. }
  5034. static int dsi_display_drm_ext_atomic_check(struct drm_connector *connector,
  5035. void *disp,
  5036. struct drm_atomic_state *state)
  5037. {
  5038. struct dsi_display *display = disp;
  5039. struct drm_connector_state *c_state;
  5040. c_state = drm_atomic_get_new_connector_state(state, connector);
  5041. return display->ext_conn->helper_private->atomic_check(
  5042. display->ext_conn, state);
  5043. }
  5044. static int dsi_display_ext_get_info(struct drm_connector *connector,
  5045. struct msm_display_info *info, void *disp)
  5046. {
  5047. struct dsi_display *display;
  5048. int i;
  5049. if (!info || !disp) {
  5050. DSI_ERR("invalid params\n");
  5051. return -EINVAL;
  5052. }
  5053. display = disp;
  5054. if (!display->panel) {
  5055. DSI_ERR("invalid display panel\n");
  5056. return -EINVAL;
  5057. }
  5058. mutex_lock(&display->display_lock);
  5059. memset(info, 0, sizeof(struct msm_display_info));
  5060. info->intf_type = DRM_MODE_CONNECTOR_DSI;
  5061. info->num_of_h_tiles = display->ctrl_count;
  5062. for (i = 0; i < info->num_of_h_tiles; i++)
  5063. info->h_tile_instance[i] = display->ctrl[i].ctrl->cell_index;
  5064. info->is_connected = connector->status != connector_status_disconnected;
  5065. if (!strcmp(display->display_type, "primary"))
  5066. info->display_type = SDE_CONNECTOR_PRIMARY;
  5067. else if (!strcmp(display->display_type, "secondary"))
  5068. info->display_type = SDE_CONNECTOR_SECONDARY;
  5069. info->capabilities |= (MSM_DISPLAY_CAP_VID_MODE |
  5070. MSM_DISPLAY_CAP_EDID | MSM_DISPLAY_CAP_HOT_PLUG);
  5071. info->curr_panel_mode = MSM_DISPLAY_VIDEO_MODE;
  5072. mutex_unlock(&display->display_lock);
  5073. return 0;
  5074. }
  5075. static int dsi_display_ext_get_mode_info(struct drm_connector *connector,
  5076. const struct drm_display_mode *drm_mode,
  5077. struct msm_mode_info *mode_info,
  5078. void *display, const struct msm_resource_caps_info *avail_res)
  5079. {
  5080. struct msm_display_topology *topology;
  5081. if (!drm_mode || !mode_info ||
  5082. !avail_res || !avail_res->max_mixer_width)
  5083. return -EINVAL;
  5084. memset(mode_info, 0, sizeof(*mode_info));
  5085. mode_info->frame_rate = drm_mode->vrefresh;
  5086. mode_info->vtotal = drm_mode->vtotal;
  5087. topology = &mode_info->topology;
  5088. topology->num_lm = (avail_res->max_mixer_width
  5089. <= drm_mode->hdisplay) ? 2 : 1;
  5090. topology->num_enc = 0;
  5091. topology->num_intf = topology->num_lm;
  5092. mode_info->comp_info.comp_type = MSM_DISPLAY_COMPRESSION_NONE;
  5093. return 0;
  5094. }
  5095. static struct dsi_display_ext_bridge *dsi_display_ext_get_bridge(
  5096. struct drm_bridge *bridge)
  5097. {
  5098. struct msm_drm_private *priv;
  5099. struct sde_kms *sde_kms;
  5100. struct drm_connector *conn;
  5101. struct drm_connector_list_iter conn_iter;
  5102. struct sde_connector *sde_conn;
  5103. struct dsi_display *display;
  5104. struct dsi_display_ext_bridge *dsi_bridge = NULL;
  5105. int i;
  5106. if (!bridge || !bridge->encoder) {
  5107. SDE_ERROR("invalid argument\n");
  5108. return NULL;
  5109. }
  5110. priv = bridge->dev->dev_private;
  5111. sde_kms = to_sde_kms(priv->kms);
  5112. drm_connector_list_iter_begin(sde_kms->dev, &conn_iter);
  5113. drm_for_each_connector_iter(conn, &conn_iter) {
  5114. sde_conn = to_sde_connector(conn);
  5115. if (sde_conn->encoder == bridge->encoder) {
  5116. display = sde_conn->display;
  5117. display_for_each_ctrl(i, display) {
  5118. if (display->ext_bridge[i].bridge == bridge) {
  5119. dsi_bridge = &display->ext_bridge[i];
  5120. break;
  5121. }
  5122. }
  5123. }
  5124. }
  5125. drm_connector_list_iter_end(&conn_iter);
  5126. return dsi_bridge;
  5127. }
  5128. static void dsi_display_drm_ext_adjust_timing(
  5129. const struct dsi_display *display,
  5130. struct drm_display_mode *mode)
  5131. {
  5132. mode->hdisplay /= display->ctrl_count;
  5133. mode->hsync_start /= display->ctrl_count;
  5134. mode->hsync_end /= display->ctrl_count;
  5135. mode->htotal /= display->ctrl_count;
  5136. mode->hskew /= display->ctrl_count;
  5137. mode->clock /= display->ctrl_count;
  5138. }
  5139. static enum drm_mode_status dsi_display_drm_ext_bridge_mode_valid(
  5140. struct drm_bridge *bridge,
  5141. const struct drm_display_mode *mode)
  5142. {
  5143. struct dsi_display_ext_bridge *ext_bridge;
  5144. struct drm_display_mode tmp;
  5145. ext_bridge = dsi_display_ext_get_bridge(bridge);
  5146. if (!ext_bridge)
  5147. return MODE_ERROR;
  5148. tmp = *mode;
  5149. dsi_display_drm_ext_adjust_timing(ext_bridge->display, &tmp);
  5150. return ext_bridge->orig_funcs->mode_valid(bridge, &tmp);
  5151. }
  5152. static bool dsi_display_drm_ext_bridge_mode_fixup(
  5153. struct drm_bridge *bridge,
  5154. const struct drm_display_mode *mode,
  5155. struct drm_display_mode *adjusted_mode)
  5156. {
  5157. struct dsi_display_ext_bridge *ext_bridge;
  5158. struct drm_display_mode tmp;
  5159. ext_bridge = dsi_display_ext_get_bridge(bridge);
  5160. if (!ext_bridge)
  5161. return false;
  5162. tmp = *mode;
  5163. dsi_display_drm_ext_adjust_timing(ext_bridge->display, &tmp);
  5164. return ext_bridge->orig_funcs->mode_fixup(bridge, &tmp, &tmp);
  5165. }
  5166. static void dsi_display_drm_ext_bridge_mode_set(
  5167. struct drm_bridge *bridge,
  5168. const struct drm_display_mode *mode,
  5169. const struct drm_display_mode *adjusted_mode)
  5170. {
  5171. struct dsi_display_ext_bridge *ext_bridge;
  5172. struct drm_display_mode tmp;
  5173. ext_bridge = dsi_display_ext_get_bridge(bridge);
  5174. if (!ext_bridge)
  5175. return;
  5176. tmp = *mode;
  5177. dsi_display_drm_ext_adjust_timing(ext_bridge->display, &tmp);
  5178. ext_bridge->orig_funcs->mode_set(bridge, &tmp, &tmp);
  5179. }
  5180. static int dsi_host_ext_attach(struct mipi_dsi_host *host,
  5181. struct mipi_dsi_device *dsi)
  5182. {
  5183. struct dsi_display *display = to_dsi_display(host);
  5184. struct dsi_panel *panel;
  5185. if (!host || !dsi || !display->panel) {
  5186. DSI_ERR("Invalid param\n");
  5187. return -EINVAL;
  5188. }
  5189. DSI_DEBUG("DSI[%s]: channel=%d, lanes=%d, format=%d, mode_flags=%lx\n",
  5190. dsi->name, dsi->channel, dsi->lanes,
  5191. dsi->format, dsi->mode_flags);
  5192. panel = display->panel;
  5193. panel->host_config.data_lanes = 0;
  5194. if (dsi->lanes > 0)
  5195. panel->host_config.data_lanes |= DSI_DATA_LANE_0;
  5196. if (dsi->lanes > 1)
  5197. panel->host_config.data_lanes |= DSI_DATA_LANE_1;
  5198. if (dsi->lanes > 2)
  5199. panel->host_config.data_lanes |= DSI_DATA_LANE_2;
  5200. if (dsi->lanes > 3)
  5201. panel->host_config.data_lanes |= DSI_DATA_LANE_3;
  5202. switch (dsi->format) {
  5203. case MIPI_DSI_FMT_RGB888:
  5204. panel->host_config.dst_format = DSI_PIXEL_FORMAT_RGB888;
  5205. break;
  5206. case MIPI_DSI_FMT_RGB666:
  5207. panel->host_config.dst_format = DSI_PIXEL_FORMAT_RGB666_LOOSE;
  5208. break;
  5209. case MIPI_DSI_FMT_RGB666_PACKED:
  5210. panel->host_config.dst_format = DSI_PIXEL_FORMAT_RGB666;
  5211. break;
  5212. case MIPI_DSI_FMT_RGB565:
  5213. default:
  5214. panel->host_config.dst_format = DSI_PIXEL_FORMAT_RGB565;
  5215. break;
  5216. }
  5217. if (dsi->mode_flags & MIPI_DSI_MODE_VIDEO) {
  5218. panel->panel_mode = DSI_OP_VIDEO_MODE;
  5219. if (dsi->mode_flags & MIPI_DSI_MODE_VIDEO_BURST)
  5220. panel->video_config.traffic_mode =
  5221. DSI_VIDEO_TRAFFIC_BURST_MODE;
  5222. else if (dsi->mode_flags & MIPI_DSI_MODE_VIDEO_SYNC_PULSE)
  5223. panel->video_config.traffic_mode =
  5224. DSI_VIDEO_TRAFFIC_SYNC_PULSES;
  5225. else
  5226. panel->video_config.traffic_mode =
  5227. DSI_VIDEO_TRAFFIC_SYNC_START_EVENTS;
  5228. panel->video_config.hsa_lp11_en =
  5229. dsi->mode_flags & MIPI_DSI_MODE_VIDEO_HSA;
  5230. panel->video_config.hbp_lp11_en =
  5231. dsi->mode_flags & MIPI_DSI_MODE_VIDEO_HBP;
  5232. panel->video_config.hfp_lp11_en =
  5233. dsi->mode_flags & MIPI_DSI_MODE_VIDEO_HFP;
  5234. panel->video_config.pulse_mode_hsa_he =
  5235. dsi->mode_flags & MIPI_DSI_MODE_VIDEO_HSE;
  5236. panel->video_config.bllp_lp11_en =
  5237. dsi->mode_flags & MIPI_DSI_MODE_VIDEO_BLLP;
  5238. panel->video_config.eof_bllp_lp11_en =
  5239. dsi->mode_flags & MIPI_DSI_MODE_VIDEO_EOF_BLLP;
  5240. } else {
  5241. panel->panel_mode = DSI_OP_CMD_MODE;
  5242. DSI_ERR("command mode not supported by ext bridge\n");
  5243. return -ENOTSUPP;
  5244. }
  5245. panel->bl_config.type = DSI_BACKLIGHT_UNKNOWN;
  5246. return 0;
  5247. }
  5248. static struct mipi_dsi_host_ops dsi_host_ext_ops = {
  5249. .attach = dsi_host_ext_attach,
  5250. .detach = dsi_host_detach,
  5251. .transfer = dsi_host_transfer,
  5252. };
  5253. struct drm_panel *dsi_display_get_drm_panel(struct dsi_display *display)
  5254. {
  5255. if (!display || !display->panel) {
  5256. pr_err("invalid param(s)\n");
  5257. return NULL;
  5258. }
  5259. return &display->panel->drm_panel;
  5260. }
  5261. int dsi_display_drm_ext_bridge_init(struct dsi_display *display,
  5262. struct drm_encoder *encoder, struct drm_connector *connector)
  5263. {
  5264. struct drm_device *drm;
  5265. struct drm_bridge *bridge;
  5266. struct drm_bridge *ext_bridge;
  5267. struct drm_connector *ext_conn;
  5268. struct sde_connector *sde_conn;
  5269. struct drm_bridge *prev_bridge;
  5270. int rc = 0, i;
  5271. if (!display || !encoder || !connector)
  5272. return -EINVAL;
  5273. drm = encoder->dev;
  5274. bridge = encoder->bridge;
  5275. sde_conn = to_sde_connector(connector);
  5276. prev_bridge = bridge;
  5277. if (display->panel && !display->panel->host_config.ext_bridge_mode)
  5278. return 0;
  5279. for (i = 0; i < display->ext_bridge_cnt; i++) {
  5280. struct dsi_display_ext_bridge *ext_bridge_info =
  5281. &display->ext_bridge[i];
  5282. /* return if ext bridge is already initialized */
  5283. if (ext_bridge_info->bridge)
  5284. return 0;
  5285. ext_bridge = of_drm_find_bridge(ext_bridge_info->node_of);
  5286. if (IS_ERR_OR_NULL(ext_bridge)) {
  5287. rc = PTR_ERR(ext_bridge);
  5288. DSI_ERR("failed to find ext bridge\n");
  5289. goto error;
  5290. }
  5291. /* override functions for mode adjustment */
  5292. if (display->ext_bridge_cnt > 1) {
  5293. ext_bridge_info->bridge_funcs = *ext_bridge->funcs;
  5294. if (ext_bridge->funcs->mode_fixup)
  5295. ext_bridge_info->bridge_funcs.mode_fixup =
  5296. dsi_display_drm_ext_bridge_mode_fixup;
  5297. if (ext_bridge->funcs->mode_valid)
  5298. ext_bridge_info->bridge_funcs.mode_valid =
  5299. dsi_display_drm_ext_bridge_mode_valid;
  5300. if (ext_bridge->funcs->mode_set)
  5301. ext_bridge_info->bridge_funcs.mode_set =
  5302. dsi_display_drm_ext_bridge_mode_set;
  5303. ext_bridge_info->orig_funcs = ext_bridge->funcs;
  5304. ext_bridge->funcs = &ext_bridge_info->bridge_funcs;
  5305. }
  5306. rc = drm_bridge_attach(encoder, ext_bridge, prev_bridge);
  5307. if (rc) {
  5308. DSI_ERR("[%s] ext brige attach failed, %d\n",
  5309. display->name, rc);
  5310. goto error;
  5311. }
  5312. ext_bridge_info->display = display;
  5313. ext_bridge_info->bridge = ext_bridge;
  5314. prev_bridge = ext_bridge;
  5315. /* ext bridge will init its own connector during attach,
  5316. * we need to extract it out of the connector list
  5317. */
  5318. spin_lock_irq(&drm->mode_config.connector_list_lock);
  5319. ext_conn = list_last_entry(&drm->mode_config.connector_list,
  5320. struct drm_connector, head);
  5321. if (ext_conn && ext_conn != connector &&
  5322. ext_conn->encoder_ids[0] == bridge->encoder->base.id) {
  5323. list_del_init(&ext_conn->head);
  5324. display->ext_conn = ext_conn;
  5325. }
  5326. spin_unlock_irq(&drm->mode_config.connector_list_lock);
  5327. /* if there is no valid external connector created, or in split
  5328. * mode, default setting is used from panel defined in DT file.
  5329. */
  5330. if (!display->ext_conn ||
  5331. !display->ext_conn->funcs ||
  5332. !display->ext_conn->helper_private ||
  5333. display->ext_bridge_cnt > 1) {
  5334. display->ext_conn = NULL;
  5335. continue;
  5336. }
  5337. /* otherwise, hook up the functions to use external connector */
  5338. if (display->ext_conn->funcs->detect)
  5339. sde_conn->ops.detect = dsi_display_drm_ext_detect;
  5340. if (display->ext_conn->helper_private->get_modes)
  5341. sde_conn->ops.get_modes =
  5342. dsi_display_drm_ext_get_modes;
  5343. if (display->ext_conn->helper_private->mode_valid)
  5344. sde_conn->ops.mode_valid =
  5345. dsi_display_drm_ext_mode_valid;
  5346. if (display->ext_conn->helper_private->atomic_check)
  5347. sde_conn->ops.atomic_check =
  5348. dsi_display_drm_ext_atomic_check;
  5349. sde_conn->ops.get_info =
  5350. dsi_display_ext_get_info;
  5351. sde_conn->ops.get_mode_info =
  5352. dsi_display_ext_get_mode_info;
  5353. /* add support to attach/detach */
  5354. display->host.ops = &dsi_host_ext_ops;
  5355. }
  5356. return 0;
  5357. error:
  5358. return rc;
  5359. }
  5360. int dsi_display_get_info(struct drm_connector *connector,
  5361. struct msm_display_info *info, void *disp)
  5362. {
  5363. struct dsi_display *display;
  5364. struct dsi_panel_phy_props phy_props;
  5365. struct dsi_host_common_cfg *host;
  5366. int i, rc;
  5367. if (!info || !disp) {
  5368. DSI_ERR("invalid params\n");
  5369. return -EINVAL;
  5370. }
  5371. display = disp;
  5372. if (!display->panel) {
  5373. DSI_ERR("invalid display panel\n");
  5374. return -EINVAL;
  5375. }
  5376. mutex_lock(&display->display_lock);
  5377. rc = dsi_panel_get_phy_props(display->panel, &phy_props);
  5378. if (rc) {
  5379. DSI_ERR("[%s] failed to get panel phy props, rc=%d\n",
  5380. display->name, rc);
  5381. goto error;
  5382. }
  5383. memset(info, 0, sizeof(struct msm_display_info));
  5384. info->intf_type = DRM_MODE_CONNECTOR_DSI;
  5385. info->num_of_h_tiles = display->ctrl_count;
  5386. for (i = 0; i < info->num_of_h_tiles; i++)
  5387. info->h_tile_instance[i] = display->ctrl[i].ctrl->cell_index;
  5388. info->is_connected = display->is_active;
  5389. if (!strcmp(display->display_type, "primary"))
  5390. info->display_type = SDE_CONNECTOR_PRIMARY;
  5391. else if (!strcmp(display->display_type, "secondary"))
  5392. info->display_type = SDE_CONNECTOR_SECONDARY;
  5393. info->width_mm = phy_props.panel_width_mm;
  5394. info->height_mm = phy_props.panel_height_mm;
  5395. info->max_width = 1920;
  5396. info->max_height = 1080;
  5397. info->qsync_min_fps =
  5398. display->panel->qsync_min_fps;
  5399. info->poms_align_vsync = display->panel->poms_align_vsync;
  5400. switch (display->panel->panel_mode) {
  5401. case DSI_OP_VIDEO_MODE:
  5402. info->curr_panel_mode = MSM_DISPLAY_VIDEO_MODE;
  5403. info->capabilities |= MSM_DISPLAY_CAP_VID_MODE;
  5404. if (display->panel->panel_mode_switch_enabled)
  5405. info->capabilities |= MSM_DISPLAY_CAP_CMD_MODE;
  5406. break;
  5407. case DSI_OP_CMD_MODE:
  5408. info->curr_panel_mode = MSM_DISPLAY_CMD_MODE;
  5409. info->capabilities |= MSM_DISPLAY_CAP_CMD_MODE;
  5410. if (display->panel->panel_mode_switch_enabled)
  5411. info->capabilities |= MSM_DISPLAY_CAP_VID_MODE;
  5412. info->is_te_using_watchdog_timer =
  5413. display->panel->te_using_watchdog_timer |
  5414. display->sw_te_using_wd;
  5415. break;
  5416. default:
  5417. DSI_ERR("unknwown dsi panel mode %d\n",
  5418. display->panel->panel_mode);
  5419. break;
  5420. }
  5421. if (display->panel->esd_config.esd_enabled &&
  5422. !display->sw_te_using_wd)
  5423. info->capabilities |= MSM_DISPLAY_ESD_ENABLED;
  5424. info->te_source = display->te_source;
  5425. host = &display->panel->host_config;
  5426. if (host->split_link.split_link_enabled)
  5427. info->capabilities |= MSM_DISPLAY_SPLIT_LINK;
  5428. info->dsc_count = display->panel->dsc_count;
  5429. info->lm_count = display->panel->lm_count;
  5430. error:
  5431. mutex_unlock(&display->display_lock);
  5432. return rc;
  5433. }
  5434. int dsi_display_get_mode_count(struct dsi_display *display,
  5435. u32 *count)
  5436. {
  5437. if (!display || !display->panel) {
  5438. DSI_ERR("invalid display:%d panel:%d\n", display != NULL,
  5439. display ? display->panel != NULL : 0);
  5440. return -EINVAL;
  5441. }
  5442. mutex_lock(&display->display_lock);
  5443. *count = display->panel->num_display_modes;
  5444. mutex_unlock(&display->display_lock);
  5445. return 0;
  5446. }
  5447. void dsi_display_adjust_mode_timing(struct dsi_display *display,
  5448. struct dsi_display_mode *dsi_mode,
  5449. int lanes, int bpp)
  5450. {
  5451. u64 new_htotal, new_vtotal, htotal, vtotal, old_htotal, div;
  5452. struct dsi_dyn_clk_caps *dyn_clk_caps;
  5453. u32 bits_per_symbol = 16, num_of_symbols = 7; /* For Cphy */
  5454. dyn_clk_caps = &(display->panel->dyn_clk_caps);
  5455. /* Constant FPS is not supported on command mode */
  5456. if (dsi_mode->panel_mode == DSI_OP_CMD_MODE)
  5457. return;
  5458. if (!dyn_clk_caps->maintain_const_fps)
  5459. return;
  5460. /*
  5461. * When there is a dynamic clock switch, there is small change
  5462. * in FPS. To compensate for this difference in FPS, hfp or vfp
  5463. * is adjusted. It has been assumed that the refined porch values
  5464. * are supported by the panel. This logic can be enhanced further
  5465. * in future by taking min/max porches supported by the panel.
  5466. */
  5467. switch (dyn_clk_caps->type) {
  5468. case DSI_DYN_CLK_TYPE_CONST_FPS_ADJUST_HFP:
  5469. vtotal = DSI_V_TOTAL(&dsi_mode->timing);
  5470. old_htotal = dsi_h_total_dce(&dsi_mode->timing);
  5471. do_div(old_htotal, display->ctrl_count);
  5472. new_htotal = dsi_mode->timing.clk_rate_hz * lanes;
  5473. div = bpp * vtotal * dsi_mode->timing.refresh_rate;
  5474. if (dsi_display_is_type_cphy(display)) {
  5475. new_htotal = new_htotal * bits_per_symbol;
  5476. div = div * num_of_symbols;
  5477. }
  5478. do_div(new_htotal, div);
  5479. if (old_htotal > new_htotal)
  5480. dsi_mode->timing.h_front_porch -=
  5481. ((old_htotal - new_htotal) * display->ctrl_count);
  5482. else
  5483. dsi_mode->timing.h_front_porch +=
  5484. ((new_htotal - old_htotal) * display->ctrl_count);
  5485. break;
  5486. case DSI_DYN_CLK_TYPE_CONST_FPS_ADJUST_VFP:
  5487. htotal = dsi_h_total_dce(&dsi_mode->timing);
  5488. do_div(htotal, display->ctrl_count);
  5489. new_vtotal = dsi_mode->timing.clk_rate_hz * lanes;
  5490. div = bpp * htotal * dsi_mode->timing.refresh_rate;
  5491. if (dsi_display_is_type_cphy(display)) {
  5492. new_vtotal = new_vtotal * bits_per_symbol;
  5493. div = div * num_of_symbols;
  5494. }
  5495. do_div(new_vtotal, div);
  5496. dsi_mode->timing.v_front_porch = new_vtotal -
  5497. dsi_mode->timing.v_back_porch -
  5498. dsi_mode->timing.v_sync_width -
  5499. dsi_mode->timing.v_active;
  5500. break;
  5501. default:
  5502. break;
  5503. }
  5504. }
  5505. static void _dsi_display_populate_bit_clks(struct dsi_display *display,
  5506. int start, int end, u32 *mode_idx)
  5507. {
  5508. struct dsi_dyn_clk_caps *dyn_clk_caps;
  5509. struct dsi_display_mode *src, *dst;
  5510. struct dsi_host_common_cfg *cfg;
  5511. struct dsi_display_mode_priv_info *priv_info;
  5512. int i, j, total_modes, bpp, lanes = 0;
  5513. size_t size = 0;
  5514. if (!display || !mode_idx)
  5515. return;
  5516. dyn_clk_caps = &(display->panel->dyn_clk_caps);
  5517. if (!dyn_clk_caps->dyn_clk_support)
  5518. return;
  5519. cfg = &(display->panel->host_config);
  5520. bpp = dsi_pixel_format_to_bpp(cfg->dst_format);
  5521. if (cfg->data_lanes & DSI_DATA_LANE_0)
  5522. lanes++;
  5523. if (cfg->data_lanes & DSI_DATA_LANE_1)
  5524. lanes++;
  5525. if (cfg->data_lanes & DSI_DATA_LANE_2)
  5526. lanes++;
  5527. if (cfg->data_lanes & DSI_DATA_LANE_3)
  5528. lanes++;
  5529. total_modes = display->panel->num_display_modes;
  5530. for (i = start; i < end; i++) {
  5531. src = &display->modes[i];
  5532. if (!src)
  5533. return;
  5534. /*
  5535. * TODO: currently setting the first bit rate in
  5536. * the list as preferred rate. But ideally should
  5537. * be based on user or device tree preferrence.
  5538. */
  5539. src->timing.clk_rate_hz = dyn_clk_caps->bit_clk_list[0];
  5540. dsi_display_adjust_mode_timing(display, src, lanes, bpp);
  5541. src->pixel_clk_khz =
  5542. div_u64(src->timing.clk_rate_hz * lanes, bpp);
  5543. src->pixel_clk_khz /= 1000;
  5544. src->pixel_clk_khz *= display->ctrl_count;
  5545. }
  5546. for (i = 1; i < dyn_clk_caps->bit_clk_list_len; i++) {
  5547. if (*mode_idx >= total_modes)
  5548. return;
  5549. for (j = start; j < end; j++) {
  5550. src = &display->modes[j];
  5551. dst = &display->modes[*mode_idx];
  5552. if (!src || !dst) {
  5553. DSI_ERR("invalid mode index\n");
  5554. return;
  5555. }
  5556. memcpy(dst, src, sizeof(struct dsi_display_mode));
  5557. size = sizeof(struct dsi_display_mode_priv_info);
  5558. priv_info = kzalloc(size, GFP_KERNEL);
  5559. dst->priv_info = priv_info;
  5560. if (dst->priv_info)
  5561. memcpy(dst->priv_info, src->priv_info, size);
  5562. dst->timing.clk_rate_hz = dyn_clk_caps->bit_clk_list[i];
  5563. dsi_display_adjust_mode_timing(display, dst, lanes,
  5564. bpp);
  5565. dst->pixel_clk_khz =
  5566. div_u64(dst->timing.clk_rate_hz * lanes, bpp);
  5567. dst->pixel_clk_khz /= 1000;
  5568. dst->pixel_clk_khz *= display->ctrl_count;
  5569. (*mode_idx)++;
  5570. }
  5571. }
  5572. }
  5573. void dsi_display_put_mode(struct dsi_display *display,
  5574. struct dsi_display_mode *mode)
  5575. {
  5576. dsi_panel_put_mode(mode);
  5577. }
  5578. int dsi_display_get_modes(struct dsi_display *display,
  5579. struct dsi_display_mode **out_modes)
  5580. {
  5581. struct dsi_dfps_capabilities dfps_caps;
  5582. struct dsi_display_ctrl *ctrl;
  5583. struct dsi_host_common_cfg *host = &display->panel->host_config;
  5584. bool is_split_link, is_cmd_mode;
  5585. u32 num_dfps_rates, timing_mode_count, display_mode_count;
  5586. u32 sublinks_count, mode_idx, array_idx = 0;
  5587. struct dsi_dyn_clk_caps *dyn_clk_caps;
  5588. int i, start, end, rc = -EINVAL;
  5589. if (!display || !out_modes) {
  5590. DSI_ERR("Invalid params\n");
  5591. return -EINVAL;
  5592. }
  5593. *out_modes = NULL;
  5594. ctrl = &display->ctrl[0];
  5595. mutex_lock(&display->display_lock);
  5596. if (display->modes)
  5597. goto exit;
  5598. display_mode_count = display->panel->num_display_modes;
  5599. display->modes = kcalloc(display_mode_count, sizeof(*display->modes),
  5600. GFP_KERNEL);
  5601. if (!display->modes) {
  5602. rc = -ENOMEM;
  5603. goto error;
  5604. }
  5605. rc = dsi_panel_get_dfps_caps(display->panel, &dfps_caps);
  5606. if (rc) {
  5607. DSI_ERR("[%s] failed to get dfps caps from panel\n",
  5608. display->name);
  5609. goto error;
  5610. }
  5611. dyn_clk_caps = &(display->panel->dyn_clk_caps);
  5612. timing_mode_count = display->panel->num_timing_nodes;
  5613. /* Validate command line timing */
  5614. if ((display->cmdline_timing != NO_OVERRIDE) &&
  5615. (display->cmdline_timing >= timing_mode_count))
  5616. display->cmdline_timing = NO_OVERRIDE;
  5617. for (mode_idx = 0; mode_idx < timing_mode_count; mode_idx++) {
  5618. struct dsi_display_mode display_mode;
  5619. int topology_override = NO_OVERRIDE;
  5620. bool is_preferred = false;
  5621. u32 frame_threshold_us = ctrl->ctrl->frame_threshold_time_us;
  5622. if (display->cmdline_timing == mode_idx) {
  5623. topology_override = display->cmdline_topology;
  5624. is_preferred = true;
  5625. }
  5626. memset(&display_mode, 0, sizeof(display_mode));
  5627. rc = dsi_panel_get_mode(display->panel, mode_idx,
  5628. &display_mode,
  5629. topology_override);
  5630. if (rc) {
  5631. DSI_ERR("[%s] failed to get mode idx %d from panel\n",
  5632. display->name, mode_idx);
  5633. goto error;
  5634. }
  5635. is_cmd_mode = (display_mode.panel_mode == DSI_OP_CMD_MODE);
  5636. /* Setup widebus support */
  5637. display_mode.priv_info->widebus_support =
  5638. ctrl->ctrl->hw.widebus_support;
  5639. num_dfps_rates = ((!dfps_caps.dfps_support ||
  5640. is_cmd_mode) ? 1 : dfps_caps.dfps_list_len);
  5641. /* Calculate dsi frame transfer time */
  5642. if (is_cmd_mode) {
  5643. dsi_panel_calc_dsi_transfer_time(
  5644. &display->panel->host_config,
  5645. &display_mode, frame_threshold_us);
  5646. display_mode.priv_info->dsi_transfer_time_us =
  5647. display_mode.timing.dsi_transfer_time_us;
  5648. display_mode.priv_info->min_dsi_clk_hz =
  5649. display_mode.timing.min_dsi_clk_hz;
  5650. display_mode.priv_info->mdp_transfer_time_us =
  5651. display_mode.timing.mdp_transfer_time_us;
  5652. }
  5653. is_split_link = host->split_link.split_link_enabled;
  5654. sublinks_count = host->split_link.num_sublinks;
  5655. if (is_split_link && sublinks_count > 1) {
  5656. display_mode.timing.h_active *= sublinks_count;
  5657. display_mode.timing.h_front_porch *= sublinks_count;
  5658. display_mode.timing.h_sync_width *= sublinks_count;
  5659. display_mode.timing.h_back_porch *= sublinks_count;
  5660. display_mode.timing.h_skew *= sublinks_count;
  5661. display_mode.pixel_clk_khz *= sublinks_count;
  5662. } else {
  5663. display_mode.timing.h_active *= display->ctrl_count;
  5664. display_mode.timing.h_front_porch *=
  5665. display->ctrl_count;
  5666. display_mode.timing.h_sync_width *=
  5667. display->ctrl_count;
  5668. display_mode.timing.h_back_porch *=
  5669. display->ctrl_count;
  5670. display_mode.timing.h_skew *= display->ctrl_count;
  5671. display_mode.pixel_clk_khz *= display->ctrl_count;
  5672. }
  5673. start = array_idx;
  5674. for (i = 0; i < num_dfps_rates; i++) {
  5675. struct dsi_display_mode *sub_mode =
  5676. &display->modes[array_idx];
  5677. u32 curr_refresh_rate;
  5678. if (!sub_mode) {
  5679. DSI_ERR("invalid mode data\n");
  5680. rc = -EFAULT;
  5681. goto error;
  5682. }
  5683. memcpy(sub_mode, &display_mode, sizeof(display_mode));
  5684. array_idx++;
  5685. if (!dfps_caps.dfps_support || is_cmd_mode)
  5686. continue;
  5687. curr_refresh_rate = sub_mode->timing.refresh_rate;
  5688. sub_mode->timing.refresh_rate = dfps_caps.dfps_list[i];
  5689. dsi_display_get_dfps_timing(display, sub_mode,
  5690. curr_refresh_rate);
  5691. }
  5692. end = array_idx;
  5693. /*
  5694. * if POMS is enabled and boot up mode is video mode,
  5695. * skip bit clk rates update for command mode,
  5696. * else if dynamic clk switch is supported then update all
  5697. * the bit clk rates.
  5698. */
  5699. if (is_cmd_mode &&
  5700. (display->panel->panel_mode == DSI_OP_VIDEO_MODE))
  5701. continue;
  5702. _dsi_display_populate_bit_clks(display, start, end, &array_idx);
  5703. if (is_preferred) {
  5704. /* Set first timing sub mode as preferred mode */
  5705. display->modes[start].is_preferred = true;
  5706. }
  5707. }
  5708. exit:
  5709. *out_modes = display->modes;
  5710. rc = 0;
  5711. error:
  5712. if (rc)
  5713. kfree(display->modes);
  5714. mutex_unlock(&display->display_lock);
  5715. return rc;
  5716. }
  5717. int dsi_display_get_panel_vfp(void *dsi_display,
  5718. int h_active, int v_active)
  5719. {
  5720. int i, rc = 0;
  5721. u32 count, refresh_rate = 0;
  5722. struct dsi_dfps_capabilities dfps_caps;
  5723. struct dsi_display *display = (struct dsi_display *)dsi_display;
  5724. struct dsi_host_common_cfg *host;
  5725. if (!display || !display->panel)
  5726. return -EINVAL;
  5727. mutex_lock(&display->display_lock);
  5728. count = display->panel->num_display_modes;
  5729. if (display->panel->cur_mode)
  5730. refresh_rate = display->panel->cur_mode->timing.refresh_rate;
  5731. dsi_panel_get_dfps_caps(display->panel, &dfps_caps);
  5732. if (dfps_caps.dfps_support)
  5733. refresh_rate = dfps_caps.max_refresh_rate;
  5734. if (!refresh_rate) {
  5735. mutex_unlock(&display->display_lock);
  5736. DSI_ERR("Null Refresh Rate\n");
  5737. return -EINVAL;
  5738. }
  5739. host = &display->panel->host_config;
  5740. if (host->split_link.split_link_enabled)
  5741. h_active *= host->split_link.num_sublinks;
  5742. else
  5743. h_active *= display->ctrl_count;
  5744. for (i = 0; i < count; i++) {
  5745. struct dsi_display_mode *m = &display->modes[i];
  5746. if (m && v_active == m->timing.v_active &&
  5747. h_active == m->timing.h_active &&
  5748. refresh_rate == m->timing.refresh_rate) {
  5749. rc = m->timing.v_front_porch;
  5750. break;
  5751. }
  5752. }
  5753. mutex_unlock(&display->display_lock);
  5754. return rc;
  5755. }
  5756. int dsi_display_get_default_lms(void *dsi_display, u32 *num_lm)
  5757. {
  5758. struct dsi_display *display = (struct dsi_display *)dsi_display;
  5759. u32 count, i;
  5760. int rc = 0;
  5761. *num_lm = 0;
  5762. mutex_lock(&display->display_lock);
  5763. count = display->panel->num_display_modes;
  5764. mutex_unlock(&display->display_lock);
  5765. if (!display->modes) {
  5766. struct dsi_display_mode *m;
  5767. rc = dsi_display_get_modes(display, &m);
  5768. if (rc)
  5769. return rc;
  5770. }
  5771. mutex_lock(&display->display_lock);
  5772. for (i = 0; i < count; i++) {
  5773. struct dsi_display_mode *m = &display->modes[i];
  5774. *num_lm = max(m->priv_info->topology.num_lm, *num_lm);
  5775. }
  5776. mutex_unlock(&display->display_lock);
  5777. return rc;
  5778. }
  5779. int dsi_display_find_mode(struct dsi_display *display,
  5780. const struct dsi_display_mode *cmp,
  5781. struct dsi_display_mode **out_mode)
  5782. {
  5783. u32 count, i;
  5784. int rc;
  5785. if (!display || !out_mode)
  5786. return -EINVAL;
  5787. *out_mode = NULL;
  5788. mutex_lock(&display->display_lock);
  5789. count = display->panel->num_display_modes;
  5790. mutex_unlock(&display->display_lock);
  5791. if (!display->modes) {
  5792. struct dsi_display_mode *m;
  5793. rc = dsi_display_get_modes(display, &m);
  5794. if (rc)
  5795. return rc;
  5796. }
  5797. mutex_lock(&display->display_lock);
  5798. for (i = 0; i < count; i++) {
  5799. struct dsi_display_mode *m = &display->modes[i];
  5800. if (cmp->timing.v_active == m->timing.v_active &&
  5801. cmp->timing.h_active == m->timing.h_active &&
  5802. cmp->timing.refresh_rate == m->timing.refresh_rate &&
  5803. cmp->panel_mode == m->panel_mode &&
  5804. cmp->pixel_clk_khz == m->pixel_clk_khz) {
  5805. *out_mode = m;
  5806. rc = 0;
  5807. break;
  5808. }
  5809. }
  5810. mutex_unlock(&display->display_lock);
  5811. if (!*out_mode) {
  5812. DSI_ERR("[%s] failed to find mode for v_active %u h_active %u fps %u pclk %u\n",
  5813. display->name, cmp->timing.v_active,
  5814. cmp->timing.h_active, cmp->timing.refresh_rate,
  5815. cmp->pixel_clk_khz);
  5816. rc = -ENOENT;
  5817. }
  5818. return rc;
  5819. }
  5820. static inline bool dsi_display_mode_switch_dfps(struct dsi_display_mode *cur,
  5821. struct dsi_display_mode *adj)
  5822. {
  5823. /*
  5824. * If there is a change in the hfp or vfp of the current and adjoining
  5825. * mode,then either it is a dfps mode switch or dynamic clk change with
  5826. * constant fps.
  5827. */
  5828. if ((cur->timing.h_front_porch != adj->timing.h_front_porch) ||
  5829. (cur->timing.v_front_porch != adj->timing.v_front_porch))
  5830. return true;
  5831. else
  5832. return false;
  5833. }
  5834. /**
  5835. * dsi_display_validate_mode_change() - Validate mode change case.
  5836. * @display: DSI display handle.
  5837. * @cur_mode: Current mode.
  5838. * @adj_mode: Mode to be set.
  5839. * MSM_MODE_FLAG_SEAMLESS_VRR flag is set if there
  5840. * is change in hfp or vfp but vactive and hactive are same.
  5841. * DSI_MODE_FLAG_DYN_CLK flag is set if there
  5842. * is change in clk but vactive and hactive are same.
  5843. * Return: error code.
  5844. */
  5845. int dsi_display_validate_mode_change(struct dsi_display *display,
  5846. struct dsi_display_mode *cur_mode,
  5847. struct dsi_display_mode *adj_mode)
  5848. {
  5849. int rc = 0;
  5850. struct dsi_dfps_capabilities dfps_caps;
  5851. struct dsi_dyn_clk_caps *dyn_clk_caps;
  5852. if (!display || !adj_mode) {
  5853. DSI_ERR("Invalid params\n");
  5854. return -EINVAL;
  5855. }
  5856. if (!display->panel || !display->panel->cur_mode) {
  5857. DSI_DEBUG("Current panel mode not set\n");
  5858. return rc;
  5859. }
  5860. mutex_lock(&display->display_lock);
  5861. dyn_clk_caps = &(display->panel->dyn_clk_caps);
  5862. if ((cur_mode->timing.v_active == adj_mode->timing.v_active) &&
  5863. (cur_mode->timing.h_active == adj_mode->timing.h_active) &&
  5864. (cur_mode->panel_mode == adj_mode->panel_mode)) {
  5865. /* dfps and dynamic clock with const fps use case */
  5866. if (dsi_display_mode_switch_dfps(cur_mode, adj_mode)) {
  5867. dsi_panel_get_dfps_caps(display->panel, &dfps_caps);
  5868. if (dfps_caps.dfps_support ||
  5869. dyn_clk_caps->maintain_const_fps) {
  5870. DSI_DEBUG("Mode switch is seamless variable refresh\n");
  5871. adj_mode->dsi_mode_flags |= DSI_MODE_FLAG_VRR;
  5872. SDE_EVT32(SDE_EVTLOG_FUNC_CASE1,
  5873. cur_mode->timing.refresh_rate,
  5874. adj_mode->timing.refresh_rate,
  5875. cur_mode->timing.h_front_porch,
  5876. adj_mode->timing.h_front_porch,
  5877. cur_mode->timing.v_front_porch,
  5878. adj_mode->timing.v_front_porch);
  5879. }
  5880. }
  5881. /* dynamic clk change use case */
  5882. if (cur_mode->pixel_clk_khz != adj_mode->pixel_clk_khz) {
  5883. if (dyn_clk_caps->dyn_clk_support) {
  5884. DSI_DEBUG("dynamic clk change detected\n");
  5885. if ((adj_mode->dsi_mode_flags &
  5886. DSI_MODE_FLAG_VRR) &&
  5887. (!dyn_clk_caps->maintain_const_fps)) {
  5888. DSI_ERR("dfps and dyn clk not supported in same commit\n");
  5889. rc = -ENOTSUPP;
  5890. goto error;
  5891. }
  5892. adj_mode->dsi_mode_flags |=
  5893. DSI_MODE_FLAG_DYN_CLK;
  5894. SDE_EVT32(SDE_EVTLOG_FUNC_CASE2,
  5895. cur_mode->pixel_clk_khz,
  5896. adj_mode->pixel_clk_khz);
  5897. }
  5898. }
  5899. }
  5900. error:
  5901. mutex_unlock(&display->display_lock);
  5902. return rc;
  5903. }
  5904. int dsi_display_validate_mode(struct dsi_display *display,
  5905. struct dsi_display_mode *mode,
  5906. u32 flags)
  5907. {
  5908. int rc = 0;
  5909. int i;
  5910. struct dsi_display_ctrl *ctrl;
  5911. struct dsi_display_mode adj_mode;
  5912. if (!display || !mode) {
  5913. DSI_ERR("Invalid params\n");
  5914. return -EINVAL;
  5915. }
  5916. mutex_lock(&display->display_lock);
  5917. adj_mode = *mode;
  5918. adjust_timing_by_ctrl_count(display, &adj_mode);
  5919. rc = dsi_panel_validate_mode(display->panel, &adj_mode);
  5920. if (rc) {
  5921. DSI_ERR("[%s] panel mode validation failed, rc=%d\n",
  5922. display->name, rc);
  5923. goto error;
  5924. }
  5925. display_for_each_ctrl(i, display) {
  5926. ctrl = &display->ctrl[i];
  5927. rc = dsi_ctrl_validate_timing(ctrl->ctrl, &adj_mode.timing);
  5928. if (rc) {
  5929. DSI_ERR("[%s] ctrl mode validation failed, rc=%d\n",
  5930. display->name, rc);
  5931. goto error;
  5932. }
  5933. rc = dsi_phy_validate_mode(ctrl->phy, &adj_mode.timing);
  5934. if (rc) {
  5935. DSI_ERR("[%s] phy mode validation failed, rc=%d\n",
  5936. display->name, rc);
  5937. goto error;
  5938. }
  5939. }
  5940. if ((flags & DSI_VALIDATE_FLAG_ALLOW_ADJUST) &&
  5941. (mode->dsi_mode_flags & DSI_MODE_FLAG_SEAMLESS)) {
  5942. rc = dsi_display_validate_mode_seamless(display, mode);
  5943. if (rc) {
  5944. DSI_ERR("[%s] seamless not possible rc=%d\n",
  5945. display->name, rc);
  5946. goto error;
  5947. }
  5948. }
  5949. error:
  5950. mutex_unlock(&display->display_lock);
  5951. return rc;
  5952. }
  5953. int dsi_display_set_mode(struct dsi_display *display,
  5954. struct dsi_display_mode *mode,
  5955. u32 flags)
  5956. {
  5957. int rc = 0;
  5958. struct dsi_display_mode adj_mode;
  5959. struct dsi_mode_info timing;
  5960. if (!display || !mode || !display->panel) {
  5961. DSI_ERR("Invalid params\n");
  5962. return -EINVAL;
  5963. }
  5964. mutex_lock(&display->display_lock);
  5965. adj_mode = *mode;
  5966. timing = adj_mode.timing;
  5967. adjust_timing_by_ctrl_count(display, &adj_mode);
  5968. if (!display->panel->cur_mode) {
  5969. display->panel->cur_mode =
  5970. kzalloc(sizeof(struct dsi_display_mode), GFP_KERNEL);
  5971. if (!display->panel->cur_mode) {
  5972. rc = -ENOMEM;
  5973. goto error;
  5974. }
  5975. }
  5976. /*For dynamic DSI setting, use specified clock rate */
  5977. if (display->cached_clk_rate > 0)
  5978. adj_mode.priv_info->clk_rate_hz = display->cached_clk_rate;
  5979. rc = dsi_display_validate_mode_set(display, &adj_mode, flags);
  5980. if (rc) {
  5981. DSI_ERR("[%s] mode cannot be set\n", display->name);
  5982. goto error;
  5983. }
  5984. rc = dsi_display_set_mode_sub(display, &adj_mode, flags);
  5985. if (rc) {
  5986. DSI_ERR("[%s] failed to set mode\n", display->name);
  5987. goto error;
  5988. }
  5989. DSI_INFO("mdp_transfer_time_us=%d us\n",
  5990. adj_mode.priv_info->mdp_transfer_time_us);
  5991. DSI_INFO("hactive= %d,vactive= %d,fps=%d\n",
  5992. timing.h_active, timing.v_active,
  5993. timing.refresh_rate);
  5994. memcpy(display->panel->cur_mode, &adj_mode, sizeof(adj_mode));
  5995. error:
  5996. mutex_unlock(&display->display_lock);
  5997. return rc;
  5998. }
  5999. int dsi_display_set_tpg_state(struct dsi_display *display, bool enable)
  6000. {
  6001. int rc = 0;
  6002. int i;
  6003. struct dsi_display_ctrl *ctrl;
  6004. if (!display) {
  6005. DSI_ERR("Invalid params\n");
  6006. return -EINVAL;
  6007. }
  6008. display_for_each_ctrl(i, display) {
  6009. ctrl = &display->ctrl[i];
  6010. rc = dsi_ctrl_set_tpg_state(ctrl->ctrl, enable);
  6011. if (rc) {
  6012. DSI_ERR("[%s] failed to set tpg state for host_%d\n",
  6013. display->name, i);
  6014. goto error;
  6015. }
  6016. }
  6017. display->is_tpg_enabled = enable;
  6018. error:
  6019. return rc;
  6020. }
  6021. static int dsi_display_pre_switch(struct dsi_display *display)
  6022. {
  6023. int rc = 0;
  6024. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  6025. DSI_CORE_CLK, DSI_CLK_ON);
  6026. if (rc) {
  6027. DSI_ERR("[%s] failed to enable DSI core clocks, rc=%d\n",
  6028. display->name, rc);
  6029. goto error;
  6030. }
  6031. rc = dsi_display_ctrl_update(display);
  6032. if (rc) {
  6033. DSI_ERR("[%s] failed to update DSI controller, rc=%d\n",
  6034. display->name, rc);
  6035. goto error_ctrl_clk_off;
  6036. }
  6037. if (!display->trusted_vm_env) {
  6038. rc = dsi_display_set_clk_src(display);
  6039. if (rc) {
  6040. DSI_ERR(
  6041. "[%s] failed to set DSI link clock source, rc=%d\n",
  6042. display->name, rc);
  6043. goto error_ctrl_deinit;
  6044. }
  6045. }
  6046. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  6047. DSI_LINK_CLK, DSI_CLK_ON);
  6048. if (rc) {
  6049. DSI_ERR("[%s] failed to enable DSI link clocks, rc=%d\n",
  6050. display->name, rc);
  6051. goto error_ctrl_deinit;
  6052. }
  6053. goto error;
  6054. error_ctrl_deinit:
  6055. (void)dsi_display_ctrl_deinit(display);
  6056. error_ctrl_clk_off:
  6057. (void)dsi_display_clk_ctrl(display->dsi_clk_handle,
  6058. DSI_CORE_CLK, DSI_CLK_OFF);
  6059. error:
  6060. return rc;
  6061. }
  6062. static bool _dsi_display_validate_host_state(struct dsi_display *display)
  6063. {
  6064. int i;
  6065. struct dsi_display_ctrl *ctrl;
  6066. display_for_each_ctrl(i, display) {
  6067. ctrl = &display->ctrl[i];
  6068. if (!ctrl->ctrl)
  6069. continue;
  6070. if (!dsi_ctrl_validate_host_state(ctrl->ctrl))
  6071. return false;
  6072. }
  6073. return true;
  6074. }
  6075. static void dsi_display_handle_fifo_underflow(struct work_struct *work)
  6076. {
  6077. struct dsi_display *display = NULL;
  6078. display = container_of(work, struct dsi_display, fifo_underflow_work);
  6079. if (!display || !display->panel ||
  6080. atomic_read(&display->panel->esd_recovery_pending)) {
  6081. DSI_DEBUG("Invalid recovery use case\n");
  6082. return;
  6083. }
  6084. mutex_lock(&display->display_lock);
  6085. if (!_dsi_display_validate_host_state(display)) {
  6086. mutex_unlock(&display->display_lock);
  6087. return;
  6088. }
  6089. DSI_INFO("handle DSI FIFO underflow error\n");
  6090. SDE_EVT32(SDE_EVTLOG_FUNC_ENTRY);
  6091. dsi_display_clk_ctrl(display->dsi_clk_handle,
  6092. DSI_ALL_CLKS, DSI_CLK_ON);
  6093. dsi_display_soft_reset(display);
  6094. dsi_display_clk_ctrl(display->dsi_clk_handle,
  6095. DSI_ALL_CLKS, DSI_CLK_OFF);
  6096. SDE_EVT32(SDE_EVTLOG_FUNC_EXIT);
  6097. mutex_unlock(&display->display_lock);
  6098. }
  6099. static void dsi_display_handle_fifo_overflow(struct work_struct *work)
  6100. {
  6101. struct dsi_display *display = NULL;
  6102. struct dsi_display_ctrl *ctrl;
  6103. int i, rc;
  6104. int mask = BIT(20); /* clock lane */
  6105. int (*cb_func)(void *event_usr_ptr,
  6106. uint32_t event_idx, uint32_t instance_idx,
  6107. uint32_t data0, uint32_t data1,
  6108. uint32_t data2, uint32_t data3);
  6109. void *data;
  6110. u32 version = 0;
  6111. display = container_of(work, struct dsi_display, fifo_overflow_work);
  6112. if (!display || !display->panel ||
  6113. (display->panel->panel_mode != DSI_OP_VIDEO_MODE) ||
  6114. atomic_read(&display->panel->esd_recovery_pending)) {
  6115. DSI_DEBUG("Invalid recovery use case\n");
  6116. return;
  6117. }
  6118. mutex_lock(&display->display_lock);
  6119. if (!_dsi_display_validate_host_state(display)) {
  6120. mutex_unlock(&display->display_lock);
  6121. return;
  6122. }
  6123. DSI_INFO("handle DSI FIFO overflow error\n");
  6124. SDE_EVT32(SDE_EVTLOG_FUNC_ENTRY);
  6125. dsi_display_clk_ctrl(display->dsi_clk_handle,
  6126. DSI_ALL_CLKS, DSI_CLK_ON);
  6127. /*
  6128. * below recovery sequence is not applicable to
  6129. * hw version 2.0.0, 2.1.0 and 2.2.0, so return early.
  6130. */
  6131. ctrl = &display->ctrl[display->clk_master_idx];
  6132. version = dsi_ctrl_get_hw_version(ctrl->ctrl);
  6133. if (!version || (version < 0x20020001))
  6134. goto end;
  6135. /* reset ctrl and lanes */
  6136. display_for_each_ctrl(i, display) {
  6137. ctrl = &display->ctrl[i];
  6138. rc = dsi_ctrl_reset(ctrl->ctrl, mask);
  6139. rc = dsi_phy_lane_reset(ctrl->phy);
  6140. }
  6141. /* wait for display line count to be in active area */
  6142. ctrl = &display->ctrl[display->clk_master_idx];
  6143. if (ctrl->ctrl->recovery_cb.event_cb) {
  6144. cb_func = ctrl->ctrl->recovery_cb.event_cb;
  6145. data = ctrl->ctrl->recovery_cb.event_usr_ptr;
  6146. rc = cb_func(data, SDE_CONN_EVENT_VID_FIFO_OVERFLOW,
  6147. display->clk_master_idx, 0, 0, 0, 0);
  6148. if (rc < 0) {
  6149. DSI_DEBUG("sde callback failed\n");
  6150. goto end;
  6151. }
  6152. }
  6153. /* Enable Video mode for DSI controller */
  6154. display_for_each_ctrl(i, display) {
  6155. ctrl = &display->ctrl[i];
  6156. dsi_ctrl_vid_engine_en(ctrl->ctrl, true);
  6157. }
  6158. /*
  6159. * Add sufficient delay to make sure
  6160. * pixel transmission has started
  6161. */
  6162. udelay(200);
  6163. end:
  6164. dsi_display_clk_ctrl(display->dsi_clk_handle,
  6165. DSI_ALL_CLKS, DSI_CLK_OFF);
  6166. SDE_EVT32(SDE_EVTLOG_FUNC_EXIT);
  6167. mutex_unlock(&display->display_lock);
  6168. }
  6169. static void dsi_display_handle_lp_rx_timeout(struct work_struct *work)
  6170. {
  6171. struct dsi_display *display = NULL;
  6172. struct dsi_display_ctrl *ctrl;
  6173. int i, rc;
  6174. int mask = (BIT(20) | (0xF << 16)); /* clock lane and 4 data lane */
  6175. int (*cb_func)(void *event_usr_ptr,
  6176. uint32_t event_idx, uint32_t instance_idx,
  6177. uint32_t data0, uint32_t data1,
  6178. uint32_t data2, uint32_t data3);
  6179. void *data;
  6180. u32 version = 0;
  6181. display = container_of(work, struct dsi_display, lp_rx_timeout_work);
  6182. if (!display || !display->panel ||
  6183. (display->panel->panel_mode != DSI_OP_VIDEO_MODE) ||
  6184. atomic_read(&display->panel->esd_recovery_pending)) {
  6185. DSI_DEBUG("Invalid recovery use case\n");
  6186. return;
  6187. }
  6188. mutex_lock(&display->display_lock);
  6189. if (!_dsi_display_validate_host_state(display)) {
  6190. mutex_unlock(&display->display_lock);
  6191. return;
  6192. }
  6193. DSI_INFO("handle DSI LP RX Timeout error\n");
  6194. SDE_EVT32(SDE_EVTLOG_FUNC_ENTRY);
  6195. dsi_display_clk_ctrl(display->dsi_clk_handle,
  6196. DSI_ALL_CLKS, DSI_CLK_ON);
  6197. /*
  6198. * below recovery sequence is not applicable to
  6199. * hw version 2.0.0, 2.1.0 and 2.2.0, so return early.
  6200. */
  6201. ctrl = &display->ctrl[display->clk_master_idx];
  6202. version = dsi_ctrl_get_hw_version(ctrl->ctrl);
  6203. if (!version || (version < 0x20020001))
  6204. goto end;
  6205. /* reset ctrl and lanes */
  6206. display_for_each_ctrl(i, display) {
  6207. ctrl = &display->ctrl[i];
  6208. rc = dsi_ctrl_reset(ctrl->ctrl, mask);
  6209. rc = dsi_phy_lane_reset(ctrl->phy);
  6210. }
  6211. ctrl = &display->ctrl[display->clk_master_idx];
  6212. if (ctrl->ctrl->recovery_cb.event_cb) {
  6213. cb_func = ctrl->ctrl->recovery_cb.event_cb;
  6214. data = ctrl->ctrl->recovery_cb.event_usr_ptr;
  6215. rc = cb_func(data, SDE_CONN_EVENT_VID_FIFO_OVERFLOW,
  6216. display->clk_master_idx, 0, 0, 0, 0);
  6217. if (rc < 0) {
  6218. DSI_DEBUG("Target is in suspend/shutdown\n");
  6219. goto end;
  6220. }
  6221. }
  6222. /* Enable Video mode for DSI controller */
  6223. display_for_each_ctrl(i, display) {
  6224. ctrl = &display->ctrl[i];
  6225. dsi_ctrl_vid_engine_en(ctrl->ctrl, true);
  6226. }
  6227. /*
  6228. * Add sufficient delay to make sure
  6229. * pixel transmission as started
  6230. */
  6231. udelay(200);
  6232. end:
  6233. dsi_display_clk_ctrl(display->dsi_clk_handle,
  6234. DSI_ALL_CLKS, DSI_CLK_OFF);
  6235. SDE_EVT32(SDE_EVTLOG_FUNC_EXIT);
  6236. mutex_unlock(&display->display_lock);
  6237. }
  6238. static int dsi_display_cb_error_handler(void *data,
  6239. uint32_t event_idx, uint32_t instance_idx,
  6240. uint32_t data0, uint32_t data1,
  6241. uint32_t data2, uint32_t data3)
  6242. {
  6243. struct dsi_display *display = data;
  6244. if (!display || !(display->err_workq))
  6245. return -EINVAL;
  6246. switch (event_idx) {
  6247. case DSI_FIFO_UNDERFLOW:
  6248. queue_work(display->err_workq, &display->fifo_underflow_work);
  6249. break;
  6250. case DSI_FIFO_OVERFLOW:
  6251. queue_work(display->err_workq, &display->fifo_overflow_work);
  6252. break;
  6253. case DSI_LP_Rx_TIMEOUT:
  6254. queue_work(display->err_workq, &display->lp_rx_timeout_work);
  6255. break;
  6256. default:
  6257. DSI_WARN("unhandled error interrupt: %d\n", event_idx);
  6258. break;
  6259. }
  6260. return 0;
  6261. }
  6262. static void dsi_display_register_error_handler(struct dsi_display *display)
  6263. {
  6264. int i = 0;
  6265. struct dsi_display_ctrl *ctrl;
  6266. struct dsi_event_cb_info event_info;
  6267. if (!display)
  6268. return;
  6269. display->err_workq = create_singlethread_workqueue("dsi_err_workq");
  6270. if (!display->err_workq) {
  6271. DSI_ERR("failed to create dsi workq!\n");
  6272. return;
  6273. }
  6274. INIT_WORK(&display->fifo_underflow_work,
  6275. dsi_display_handle_fifo_underflow);
  6276. INIT_WORK(&display->fifo_overflow_work,
  6277. dsi_display_handle_fifo_overflow);
  6278. INIT_WORK(&display->lp_rx_timeout_work,
  6279. dsi_display_handle_lp_rx_timeout);
  6280. memset(&event_info, 0, sizeof(event_info));
  6281. event_info.event_cb = dsi_display_cb_error_handler;
  6282. event_info.event_usr_ptr = display;
  6283. display_for_each_ctrl(i, display) {
  6284. ctrl = &display->ctrl[i];
  6285. ctrl->ctrl->irq_info.irq_err_cb = event_info;
  6286. }
  6287. }
  6288. static void dsi_display_unregister_error_handler(struct dsi_display *display)
  6289. {
  6290. int i = 0;
  6291. struct dsi_display_ctrl *ctrl;
  6292. if (!display)
  6293. return;
  6294. display_for_each_ctrl(i, display) {
  6295. ctrl = &display->ctrl[i];
  6296. memset(&ctrl->ctrl->irq_info.irq_err_cb,
  6297. 0, sizeof(struct dsi_event_cb_info));
  6298. }
  6299. if (display->err_workq) {
  6300. destroy_workqueue(display->err_workq);
  6301. display->err_workq = NULL;
  6302. }
  6303. }
  6304. int dsi_display_prepare(struct dsi_display *display)
  6305. {
  6306. int rc = 0;
  6307. struct dsi_display_mode *mode;
  6308. if (!display) {
  6309. DSI_ERR("Invalid params\n");
  6310. return -EINVAL;
  6311. }
  6312. if (!display->panel->cur_mode) {
  6313. DSI_ERR("no valid mode set for the display\n");
  6314. return -EINVAL;
  6315. }
  6316. SDE_EVT32(SDE_EVTLOG_FUNC_ENTRY);
  6317. mutex_lock(&display->display_lock);
  6318. mode = display->panel->cur_mode;
  6319. dsi_display_set_ctrl_esd_check_flag(display, false);
  6320. /* Set up ctrl isr before enabling core clk */
  6321. if (!display->trusted_vm_env)
  6322. dsi_display_ctrl_isr_configure(display, true);
  6323. if (mode->dsi_mode_flags & DSI_MODE_FLAG_DMS) {
  6324. if (display->is_cont_splash_enabled &&
  6325. display->config.panel_mode == DSI_OP_VIDEO_MODE) {
  6326. DSI_ERR("DMS not supported on first frame\n");
  6327. rc = -EINVAL;
  6328. goto error;
  6329. }
  6330. if (!is_skip_op_required(display)) {
  6331. /* update dsi ctrl for new mode */
  6332. rc = dsi_display_pre_switch(display);
  6333. if (rc)
  6334. DSI_ERR("[%s] panel pre-switch failed, rc=%d\n",
  6335. display->name, rc);
  6336. goto error;
  6337. }
  6338. }
  6339. if (!(mode->dsi_mode_flags & DSI_MODE_FLAG_POMS) &&
  6340. (!is_skip_op_required(display))) {
  6341. /*
  6342. * For continuous splash/trusted vm, we skip panel
  6343. * pre prepare since the regulator vote is already
  6344. * taken care in splash resource init
  6345. */
  6346. rc = dsi_panel_pre_prepare(display->panel);
  6347. if (rc) {
  6348. DSI_ERR("[%s] panel pre-prepare failed, rc=%d\n",
  6349. display->name, rc);
  6350. goto error;
  6351. }
  6352. }
  6353. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  6354. DSI_CORE_CLK, DSI_CLK_ON);
  6355. if (rc) {
  6356. DSI_ERR("[%s] failed to enable DSI core clocks, rc=%d\n",
  6357. display->name, rc);
  6358. goto error_panel_post_unprep;
  6359. }
  6360. /*
  6361. * If ULPS during suspend feature is enabled, then DSI PHY was
  6362. * left on during suspend. In this case, we do not need to reset/init
  6363. * PHY. This would have already been done when the CORE clocks are
  6364. * turned on. However, if cont splash is disabled, the first time DSI
  6365. * is powered on, phy init needs to be done unconditionally.
  6366. */
  6367. if (!display->panel->ulps_suspend_enabled || !display->ulps_enabled) {
  6368. rc = dsi_display_phy_sw_reset(display);
  6369. if (rc) {
  6370. DSI_ERR("[%s] failed to reset phy, rc=%d\n",
  6371. display->name, rc);
  6372. goto error_ctrl_clk_off;
  6373. }
  6374. rc = dsi_display_phy_enable(display);
  6375. if (rc) {
  6376. DSI_ERR("[%s] failed to enable DSI PHY, rc=%d\n",
  6377. display->name, rc);
  6378. goto error_ctrl_clk_off;
  6379. }
  6380. }
  6381. if (!display->trusted_vm_env) {
  6382. rc = dsi_display_set_clk_src(display);
  6383. if (rc) {
  6384. DSI_ERR(
  6385. "[%s] failed to set DSI link clock source, rc=%d\n",
  6386. display->name, rc);
  6387. goto error_phy_disable;
  6388. }
  6389. }
  6390. rc = dsi_display_ctrl_init(display);
  6391. if (rc) {
  6392. DSI_ERR("[%s] failed to setup DSI controller, rc=%d\n",
  6393. display->name, rc);
  6394. goto error_phy_disable;
  6395. }
  6396. /* Set up DSI ERROR event callback */
  6397. dsi_display_register_error_handler(display);
  6398. rc = dsi_display_ctrl_host_enable(display);
  6399. if (rc) {
  6400. DSI_ERR("[%s] failed to enable DSI host, rc=%d\n",
  6401. display->name, rc);
  6402. goto error_ctrl_deinit;
  6403. }
  6404. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  6405. DSI_LINK_CLK, DSI_CLK_ON);
  6406. if (rc) {
  6407. DSI_ERR("[%s] failed to enable DSI link clocks, rc=%d\n",
  6408. display->name, rc);
  6409. goto error_host_engine_off;
  6410. }
  6411. if (!is_skip_op_required(display)) {
  6412. /*
  6413. * For continuous splash/trusted vm, skip panel prepare and
  6414. * ctl reset since the pnael and ctrl is already in active
  6415. * state and panel on commands are not needed
  6416. */
  6417. rc = dsi_display_soft_reset(display);
  6418. if (rc) {
  6419. DSI_ERR("[%s] failed soft reset, rc=%d\n",
  6420. display->name, rc);
  6421. goto error_ctrl_link_off;
  6422. }
  6423. if (!(mode->dsi_mode_flags & DSI_MODE_FLAG_POMS)) {
  6424. rc = dsi_panel_prepare(display->panel);
  6425. if (rc) {
  6426. DSI_ERR("[%s] panel prepare failed, rc=%d\n",
  6427. display->name, rc);
  6428. goto error_ctrl_link_off;
  6429. }
  6430. }
  6431. }
  6432. goto error;
  6433. error_ctrl_link_off:
  6434. (void)dsi_display_clk_ctrl(display->dsi_clk_handle,
  6435. DSI_LINK_CLK, DSI_CLK_OFF);
  6436. error_host_engine_off:
  6437. (void)dsi_display_ctrl_host_disable(display);
  6438. error_ctrl_deinit:
  6439. (void)dsi_display_ctrl_deinit(display);
  6440. error_phy_disable:
  6441. (void)dsi_display_phy_disable(display);
  6442. error_ctrl_clk_off:
  6443. (void)dsi_display_clk_ctrl(display->dsi_clk_handle,
  6444. DSI_CORE_CLK, DSI_CLK_OFF);
  6445. error_panel_post_unprep:
  6446. (void)dsi_panel_post_unprepare(display->panel);
  6447. error:
  6448. mutex_unlock(&display->display_lock);
  6449. SDE_EVT32(SDE_EVTLOG_FUNC_EXIT);
  6450. return rc;
  6451. }
  6452. static int dsi_display_calc_ctrl_roi(const struct dsi_display *display,
  6453. const struct dsi_display_ctrl *ctrl,
  6454. const struct msm_roi_list *req_rois,
  6455. struct dsi_rect *out_roi)
  6456. {
  6457. const struct dsi_rect *bounds = &ctrl->ctrl->mode_bounds;
  6458. struct dsi_display_mode *cur_mode;
  6459. struct msm_roi_caps *roi_caps;
  6460. struct dsi_rect req_roi = { 0 };
  6461. int rc = 0;
  6462. cur_mode = display->panel->cur_mode;
  6463. if (!cur_mode)
  6464. return 0;
  6465. roi_caps = &cur_mode->priv_info->roi_caps;
  6466. if (req_rois->num_rects > roi_caps->num_roi) {
  6467. DSI_ERR("request for %d rois greater than max %d\n",
  6468. req_rois->num_rects,
  6469. roi_caps->num_roi);
  6470. rc = -EINVAL;
  6471. goto exit;
  6472. }
  6473. /**
  6474. * if no rois, user wants to reset back to full resolution
  6475. * note: h_active is already divided by ctrl_count
  6476. */
  6477. if (!req_rois->num_rects) {
  6478. *out_roi = *bounds;
  6479. goto exit;
  6480. }
  6481. /* intersect with the bounds */
  6482. req_roi.x = req_rois->roi[0].x1;
  6483. req_roi.y = req_rois->roi[0].y1;
  6484. req_roi.w = req_rois->roi[0].x2 - req_rois->roi[0].x1;
  6485. req_roi.h = req_rois->roi[0].y2 - req_rois->roi[0].y1;
  6486. dsi_rect_intersect(&req_roi, bounds, out_roi);
  6487. exit:
  6488. /* adjust the ctrl origin to be top left within the ctrl */
  6489. out_roi->x = out_roi->x - bounds->x;
  6490. DSI_DEBUG("ctrl%d:%d: req (%d,%d,%d,%d) bnd (%d,%d,%d,%d) out (%d,%d,%d,%d)\n",
  6491. ctrl->dsi_ctrl_idx, ctrl->ctrl->cell_index,
  6492. req_roi.x, req_roi.y, req_roi.w, req_roi.h,
  6493. bounds->x, bounds->y, bounds->w, bounds->h,
  6494. out_roi->x, out_roi->y, out_roi->w, out_roi->h);
  6495. return rc;
  6496. }
  6497. static int dsi_display_qsync(struct dsi_display *display, bool enable)
  6498. {
  6499. int i;
  6500. int rc = 0;
  6501. if (!display->panel->qsync_min_fps) {
  6502. DSI_ERR("%s:ERROR: qsync set, but no fps\n", __func__);
  6503. return 0;
  6504. }
  6505. mutex_lock(&display->display_lock);
  6506. display_for_each_ctrl(i, display) {
  6507. if (enable) {
  6508. /* send the commands to enable qsync */
  6509. rc = dsi_panel_send_qsync_on_dcs(display->panel, i);
  6510. if (rc) {
  6511. DSI_ERR("fail qsync ON cmds rc:%d\n", rc);
  6512. goto exit;
  6513. }
  6514. } else {
  6515. /* send the commands to enable qsync */
  6516. rc = dsi_panel_send_qsync_off_dcs(display->panel, i);
  6517. if (rc) {
  6518. DSI_ERR("fail qsync OFF cmds rc:%d\n", rc);
  6519. goto exit;
  6520. }
  6521. }
  6522. dsi_ctrl_setup_avr(display->ctrl[i].ctrl, enable);
  6523. }
  6524. exit:
  6525. SDE_EVT32(enable, display->panel->qsync_min_fps, rc);
  6526. mutex_unlock(&display->display_lock);
  6527. return rc;
  6528. }
  6529. static int dsi_display_set_roi(struct dsi_display *display,
  6530. struct msm_roi_list *rois)
  6531. {
  6532. struct dsi_display_mode *cur_mode;
  6533. struct msm_roi_caps *roi_caps;
  6534. int rc = 0;
  6535. int i;
  6536. if (!display || !rois || !display->panel)
  6537. return -EINVAL;
  6538. cur_mode = display->panel->cur_mode;
  6539. if (!cur_mode)
  6540. return 0;
  6541. roi_caps = &cur_mode->priv_info->roi_caps;
  6542. if (!roi_caps->enabled)
  6543. return 0;
  6544. display_for_each_ctrl(i, display) {
  6545. struct dsi_display_ctrl *ctrl = &display->ctrl[i];
  6546. struct dsi_rect ctrl_roi;
  6547. bool changed = false;
  6548. rc = dsi_display_calc_ctrl_roi(display, ctrl, rois, &ctrl_roi);
  6549. if (rc) {
  6550. DSI_ERR("dsi_display_calc_ctrl_roi failed rc %d\n", rc);
  6551. return rc;
  6552. }
  6553. rc = dsi_ctrl_set_roi(ctrl->ctrl, &ctrl_roi, &changed);
  6554. if (rc) {
  6555. DSI_ERR("dsi_ctrl_set_roi failed rc %d\n", rc);
  6556. return rc;
  6557. }
  6558. if (!changed)
  6559. continue;
  6560. /* send the new roi to the panel via dcs commands */
  6561. rc = dsi_panel_send_roi_dcs(display->panel, i, &ctrl_roi);
  6562. if (rc) {
  6563. DSI_ERR("dsi_panel_set_roi failed rc %d\n", rc);
  6564. return rc;
  6565. }
  6566. /* re-program the ctrl with the timing based on the new roi */
  6567. rc = dsi_ctrl_timing_setup(ctrl->ctrl);
  6568. if (rc) {
  6569. DSI_ERR("dsi_ctrl_setup failed rc %d\n", rc);
  6570. return rc;
  6571. }
  6572. }
  6573. return rc;
  6574. }
  6575. int dsi_display_pre_kickoff(struct drm_connector *connector,
  6576. struct dsi_display *display,
  6577. struct msm_display_kickoff_params *params)
  6578. {
  6579. int rc = 0, ret = 0;
  6580. int i;
  6581. /* check and setup MISR */
  6582. if (display->misr_enable)
  6583. _dsi_display_setup_misr(display);
  6584. /* dynamic DSI clock setting */
  6585. if (atomic_read(&display->clkrate_change_pending)) {
  6586. mutex_lock(&display->display_lock);
  6587. /*
  6588. * acquire panel_lock to make sure no commands are in progress
  6589. */
  6590. dsi_panel_acquire_panel_lock(display->panel);
  6591. /*
  6592. * Wait for DSI command engine not to be busy sending data
  6593. * from display engine.
  6594. * If waiting fails, return "rc" instead of below "ret" so as
  6595. * not to impact DRM commit. The clock updating would be
  6596. * deferred to the next DRM commit.
  6597. */
  6598. display_for_each_ctrl(i, display) {
  6599. struct dsi_ctrl *ctrl = display->ctrl[i].ctrl;
  6600. ret = dsi_ctrl_wait_for_cmd_mode_mdp_idle(ctrl);
  6601. if (ret)
  6602. goto wait_failure;
  6603. }
  6604. /*
  6605. * Don't check the return value so as not to impact DRM commit
  6606. * when error occurs.
  6607. */
  6608. (void)dsi_display_force_update_dsi_clk(display);
  6609. wait_failure:
  6610. /* release panel_lock */
  6611. dsi_panel_release_panel_lock(display->panel);
  6612. mutex_unlock(&display->display_lock);
  6613. }
  6614. if (!ret)
  6615. rc = dsi_display_set_roi(display, params->rois);
  6616. return rc;
  6617. }
  6618. int dsi_display_config_ctrl_for_cont_splash(struct dsi_display *display)
  6619. {
  6620. int rc = 0;
  6621. if (!display || !display->panel) {
  6622. DSI_ERR("Invalid params\n");
  6623. return -EINVAL;
  6624. }
  6625. if (!display->panel->cur_mode) {
  6626. DSI_ERR("no valid mode set for the display\n");
  6627. return -EINVAL;
  6628. }
  6629. if (display->config.panel_mode == DSI_OP_VIDEO_MODE) {
  6630. rc = dsi_display_vid_engine_enable(display);
  6631. if (rc) {
  6632. DSI_ERR("[%s]failed to enable DSI video engine, rc=%d\n",
  6633. display->name, rc);
  6634. goto error_out;
  6635. }
  6636. } else if (display->config.panel_mode == DSI_OP_CMD_MODE) {
  6637. rc = dsi_display_cmd_engine_enable(display);
  6638. if (rc) {
  6639. DSI_ERR("[%s]failed to enable DSI cmd engine, rc=%d\n",
  6640. display->name, rc);
  6641. goto error_out;
  6642. }
  6643. } else {
  6644. DSI_ERR("[%s] Invalid configuration\n", display->name);
  6645. rc = -EINVAL;
  6646. }
  6647. error_out:
  6648. return rc;
  6649. }
  6650. int dsi_display_pre_commit(void *display,
  6651. struct msm_display_conn_params *params)
  6652. {
  6653. bool enable = false;
  6654. int rc = 0;
  6655. if (!display || !params) {
  6656. pr_err("Invalid params\n");
  6657. return -EINVAL;
  6658. }
  6659. if (params->qsync_update) {
  6660. enable = (params->qsync_mode > 0) ? true : false;
  6661. rc = dsi_display_qsync(display, enable);
  6662. if (rc)
  6663. pr_err("%s failed to send qsync commands\n",
  6664. __func__);
  6665. SDE_EVT32(params->qsync_mode, rc);
  6666. }
  6667. return rc;
  6668. }
  6669. static void dsi_display_panel_id_notification(struct dsi_display *display)
  6670. {
  6671. if (display->panel_id != ~0x0 &&
  6672. display->ctrl[0].ctrl->panel_id_cb.event_cb) {
  6673. display->ctrl[0].ctrl->panel_id_cb.event_cb(
  6674. display->ctrl[0].ctrl->panel_id_cb.event_usr_ptr,
  6675. display->ctrl[0].ctrl->panel_id_cb.event_idx,
  6676. 0, ((display->panel_id & 0xffffffff00000000) >> 31),
  6677. (display->panel_id & 0xffffffff), 0, 0);
  6678. }
  6679. }
  6680. int dsi_display_enable(struct dsi_display *display)
  6681. {
  6682. int rc = 0;
  6683. struct dsi_display_mode *mode;
  6684. if (!display || !display->panel) {
  6685. DSI_ERR("Invalid params\n");
  6686. return -EINVAL;
  6687. }
  6688. if (!display->panel->cur_mode) {
  6689. DSI_ERR("no valid mode set for the display\n");
  6690. return -EINVAL;
  6691. }
  6692. SDE_EVT32(SDE_EVTLOG_FUNC_ENTRY);
  6693. /*
  6694. * Engine states and panel states are populated during splash
  6695. * resource/trusted vm and hence we return early
  6696. */
  6697. if (is_skip_op_required(display)) {
  6698. dsi_display_config_ctrl_for_cont_splash(display);
  6699. rc = dsi_display_splash_res_cleanup(display);
  6700. if (rc) {
  6701. DSI_ERR("Continuous splash res cleanup failed, rc=%d\n",
  6702. rc);
  6703. return -EINVAL;
  6704. }
  6705. display->panel->panel_initialized = true;
  6706. DSI_DEBUG("cont splash enabled, display enable not required\n");
  6707. dsi_display_panel_id_notification(display);
  6708. return 0;
  6709. }
  6710. mutex_lock(&display->display_lock);
  6711. mode = display->panel->cur_mode;
  6712. if (mode->dsi_mode_flags & DSI_MODE_FLAG_DMS) {
  6713. rc = dsi_panel_post_switch(display->panel);
  6714. if (rc) {
  6715. DSI_ERR("[%s] failed to switch DSI panel mode, rc=%d\n",
  6716. display->name, rc);
  6717. goto error;
  6718. }
  6719. } else if (!(display->panel->cur_mode->dsi_mode_flags &
  6720. DSI_MODE_FLAG_POMS)){
  6721. rc = dsi_panel_enable(display->panel);
  6722. if (rc) {
  6723. DSI_ERR("[%s] failed to enable DSI panel, rc=%d\n",
  6724. display->name, rc);
  6725. goto error;
  6726. }
  6727. }
  6728. dsi_display_panel_id_notification(display);
  6729. /* Block sending pps command if modeset is due to fps difference */
  6730. if ((mode->priv_info->dsc_enabled ||
  6731. mode->priv_info->vdc_enabled) &&
  6732. !(mode->dsi_mode_flags & DSI_MODE_FLAG_DMS_FPS)) {
  6733. rc = dsi_panel_update_pps(display->panel);
  6734. if (rc) {
  6735. DSI_ERR("[%s] panel pps cmd update failed, rc=%d\n",
  6736. display->name, rc);
  6737. goto error;
  6738. }
  6739. }
  6740. if (mode->dsi_mode_flags & DSI_MODE_FLAG_DMS) {
  6741. rc = dsi_panel_switch(display->panel);
  6742. if (rc)
  6743. DSI_ERR("[%s] failed to switch DSI panel mode, rc=%d\n",
  6744. display->name, rc);
  6745. goto error;
  6746. }
  6747. if (display->config.panel_mode == DSI_OP_VIDEO_MODE) {
  6748. DSI_DEBUG("%s:enable video timing eng\n", __func__);
  6749. rc = dsi_display_vid_engine_enable(display);
  6750. if (rc) {
  6751. DSI_ERR("[%s]failed to enable DSI video engine, rc=%d\n",
  6752. display->name, rc);
  6753. goto error_disable_panel;
  6754. }
  6755. } else if (display->config.panel_mode == DSI_OP_CMD_MODE) {
  6756. DSI_DEBUG("%s:enable command timing eng\n", __func__);
  6757. rc = dsi_display_cmd_engine_enable(display);
  6758. if (rc) {
  6759. DSI_ERR("[%s]failed to enable DSI cmd engine, rc=%d\n",
  6760. display->name, rc);
  6761. goto error_disable_panel;
  6762. }
  6763. } else {
  6764. DSI_ERR("[%s] Invalid configuration\n", display->name);
  6765. rc = -EINVAL;
  6766. goto error_disable_panel;
  6767. }
  6768. goto error;
  6769. error_disable_panel:
  6770. (void)dsi_panel_disable(display->panel);
  6771. error:
  6772. mutex_unlock(&display->display_lock);
  6773. SDE_EVT32(SDE_EVTLOG_FUNC_EXIT);
  6774. return rc;
  6775. }
  6776. int dsi_display_post_enable(struct dsi_display *display)
  6777. {
  6778. int rc = 0;
  6779. if (!display) {
  6780. DSI_ERR("Invalid params\n");
  6781. return -EINVAL;
  6782. }
  6783. mutex_lock(&display->display_lock);
  6784. if (display->panel->cur_mode->dsi_mode_flags & DSI_MODE_FLAG_POMS) {
  6785. if (display->config.panel_mode == DSI_OP_CMD_MODE)
  6786. dsi_panel_mode_switch_to_cmd(display->panel);
  6787. if (display->config.panel_mode == DSI_OP_VIDEO_MODE)
  6788. dsi_panel_mode_switch_to_vid(display->panel);
  6789. } else {
  6790. rc = dsi_panel_post_enable(display->panel);
  6791. if (rc)
  6792. DSI_ERR("[%s] panel post-enable failed, rc=%d\n",
  6793. display->name, rc);
  6794. }
  6795. /* remove the clk vote for CMD mode panels */
  6796. if (display->config.panel_mode == DSI_OP_CMD_MODE)
  6797. dsi_display_clk_ctrl(display->dsi_clk_handle,
  6798. DSI_ALL_CLKS, DSI_CLK_OFF);
  6799. mutex_unlock(&display->display_lock);
  6800. return rc;
  6801. }
  6802. int dsi_display_pre_disable(struct dsi_display *display)
  6803. {
  6804. int rc = 0;
  6805. if (!display) {
  6806. DSI_ERR("Invalid params\n");
  6807. return -EINVAL;
  6808. }
  6809. mutex_lock(&display->display_lock);
  6810. /* enable the clk vote for CMD mode panels */
  6811. if (display->config.panel_mode == DSI_OP_CMD_MODE)
  6812. dsi_display_clk_ctrl(display->dsi_clk_handle,
  6813. DSI_ALL_CLKS, DSI_CLK_ON);
  6814. if (display->poms_pending) {
  6815. if (display->config.panel_mode == DSI_OP_CMD_MODE)
  6816. dsi_panel_pre_mode_switch_to_video(display->panel);
  6817. if (display->config.panel_mode == DSI_OP_VIDEO_MODE) {
  6818. /*
  6819. * Add unbalanced vote for clock & cmd engine to enable
  6820. * async trigger of pre video to cmd mode switch.
  6821. */
  6822. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  6823. DSI_ALL_CLKS, DSI_CLK_ON);
  6824. if (rc) {
  6825. DSI_ERR("[%s]failed to enable all clocks,rc=%d",
  6826. display->name, rc);
  6827. goto exit;
  6828. }
  6829. rc = dsi_display_cmd_engine_enable(display);
  6830. if (rc) {
  6831. DSI_ERR("[%s]failed to enable cmd engine,rc=%d",
  6832. display->name, rc);
  6833. goto error_disable_clks;
  6834. }
  6835. dsi_panel_pre_mode_switch_to_cmd(display->panel);
  6836. }
  6837. } else {
  6838. rc = dsi_panel_pre_disable(display->panel);
  6839. if (rc)
  6840. DSI_ERR("[%s] panel pre-disable failed, rc=%d\n",
  6841. display->name, rc);
  6842. }
  6843. goto exit;
  6844. error_disable_clks:
  6845. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  6846. DSI_ALL_CLKS, DSI_CLK_OFF);
  6847. if (rc)
  6848. DSI_ERR("[%s] failed to disable all DSI clocks, rc=%d\n",
  6849. display->name, rc);
  6850. exit:
  6851. mutex_unlock(&display->display_lock);
  6852. return rc;
  6853. }
  6854. static void dsi_display_handle_poms_te(struct work_struct *work)
  6855. {
  6856. struct dsi_display *display = NULL;
  6857. struct delayed_work *dw = to_delayed_work(work);
  6858. struct mipi_dsi_device *dsi = NULL;
  6859. struct dsi_panel *panel = NULL;
  6860. int rc = 0;
  6861. display = container_of(dw, struct dsi_display, poms_te_work);
  6862. if (!display || !display->panel) {
  6863. DSI_ERR("Invalid params\n");
  6864. return;
  6865. }
  6866. panel = display->panel;
  6867. mutex_lock(&panel->panel_lock);
  6868. if (!dsi_panel_initialized(panel)) {
  6869. rc = -EINVAL;
  6870. goto error;
  6871. }
  6872. dsi = &panel->mipi_device;
  6873. rc = mipi_dsi_dcs_set_tear_off(dsi);
  6874. error:
  6875. mutex_unlock(&panel->panel_lock);
  6876. if (rc < 0)
  6877. DSI_ERR("failed to set tear off\n");
  6878. }
  6879. int dsi_display_disable(struct dsi_display *display)
  6880. {
  6881. int rc = 0;
  6882. if (!display) {
  6883. DSI_ERR("Invalid params\n");
  6884. return -EINVAL;
  6885. }
  6886. SDE_EVT32(SDE_EVTLOG_FUNC_ENTRY);
  6887. mutex_lock(&display->display_lock);
  6888. /* cancel delayed work */
  6889. if (display->poms_pending &&
  6890. display->panel->poms_align_vsync)
  6891. cancel_delayed_work_sync(&display->poms_te_work);
  6892. rc = dsi_display_wake_up(display);
  6893. if (rc)
  6894. DSI_ERR("[%s] display wake up failed, rc=%d\n",
  6895. display->name, rc);
  6896. if (display->config.panel_mode == DSI_OP_VIDEO_MODE) {
  6897. rc = dsi_display_vid_engine_disable(display);
  6898. if (rc)
  6899. DSI_ERR("[%s]failed to disable DSI vid engine, rc=%d\n",
  6900. display->name, rc);
  6901. } else if (display->config.panel_mode == DSI_OP_CMD_MODE) {
  6902. /**
  6903. * On POMS request , disable panel TE through
  6904. * delayed work queue.
  6905. */
  6906. if (display->poms_pending &&
  6907. display->panel->poms_align_vsync) {
  6908. INIT_DELAYED_WORK(&display->poms_te_work,
  6909. dsi_display_handle_poms_te);
  6910. queue_delayed_work(system_wq,
  6911. &display->poms_te_work,
  6912. msecs_to_jiffies(100));
  6913. }
  6914. rc = dsi_display_cmd_engine_disable(display);
  6915. if (rc)
  6916. DSI_ERR("[%s]failed to disable DSI cmd engine, rc=%d\n",
  6917. display->name, rc);
  6918. } else {
  6919. DSI_ERR("[%s] Invalid configuration\n", display->name);
  6920. rc = -EINVAL;
  6921. }
  6922. if (!display->poms_pending && !is_skip_op_required(display)) {
  6923. rc = dsi_panel_disable(display->panel);
  6924. if (rc)
  6925. DSI_ERR("[%s] failed to disable DSI panel, rc=%d\n",
  6926. display->name, rc);
  6927. }
  6928. if (is_skip_op_required(display)) {
  6929. /* applicable only for trusted vm */
  6930. display->panel->panel_initialized = false;
  6931. display->panel->power_mode = SDE_MODE_DPMS_OFF;
  6932. }
  6933. mutex_unlock(&display->display_lock);
  6934. SDE_EVT32(SDE_EVTLOG_FUNC_EXIT);
  6935. return rc;
  6936. }
  6937. int dsi_display_update_pps(char *pps_cmd, void *disp)
  6938. {
  6939. struct dsi_display *display;
  6940. if (pps_cmd == NULL || disp == NULL) {
  6941. DSI_ERR("Invalid parameter\n");
  6942. return -EINVAL;
  6943. }
  6944. display = disp;
  6945. mutex_lock(&display->display_lock);
  6946. memcpy(display->panel->dce_pps_cmd, pps_cmd, DSI_CMD_PPS_SIZE);
  6947. mutex_unlock(&display->display_lock);
  6948. return 0;
  6949. }
  6950. int dsi_display_dump_clks_state(struct dsi_display *display)
  6951. {
  6952. int rc = 0;
  6953. if (!display) {
  6954. DSI_ERR("invalid display argument\n");
  6955. return -EINVAL;
  6956. }
  6957. if (!display->clk_mngr) {
  6958. DSI_ERR("invalid clk manager\n");
  6959. return -EINVAL;
  6960. }
  6961. if (!display->dsi_clk_handle || !display->mdp_clk_handle) {
  6962. DSI_ERR("invalid clk handles\n");
  6963. return -EINVAL;
  6964. }
  6965. mutex_lock(&display->display_lock);
  6966. rc = dsi_display_dump_clk_handle_state(display->dsi_clk_handle);
  6967. if (rc) {
  6968. DSI_ERR("failed to dump dsi clock state\n");
  6969. goto end;
  6970. }
  6971. rc = dsi_display_dump_clk_handle_state(display->mdp_clk_handle);
  6972. if (rc) {
  6973. DSI_ERR("failed to dump mdp clock state\n");
  6974. goto end;
  6975. }
  6976. end:
  6977. mutex_unlock(&display->display_lock);
  6978. return rc;
  6979. }
  6980. int dsi_display_unprepare(struct dsi_display *display)
  6981. {
  6982. int rc = 0, i;
  6983. struct dsi_display_ctrl *ctrl;
  6984. if (!display) {
  6985. DSI_ERR("Invalid params\n");
  6986. return -EINVAL;
  6987. }
  6988. SDE_EVT32(SDE_EVTLOG_FUNC_ENTRY);
  6989. mutex_lock(&display->display_lock);
  6990. rc = dsi_display_wake_up(display);
  6991. if (rc)
  6992. DSI_ERR("[%s] display wake up failed, rc=%d\n",
  6993. display->name, rc);
  6994. if (!display->poms_pending && !is_skip_op_required(display)) {
  6995. rc = dsi_panel_unprepare(display->panel);
  6996. if (rc)
  6997. DSI_ERR("[%s] panel unprepare failed, rc=%d\n",
  6998. display->name, rc);
  6999. }
  7000. /* Remove additional vote added for pre_mode_switch_to_cmd */
  7001. if (display->poms_pending &&
  7002. display->config.panel_mode == DSI_OP_VIDEO_MODE) {
  7003. display_for_each_ctrl(i, display) {
  7004. ctrl = &display->ctrl[i];
  7005. if (!ctrl->ctrl || !ctrl->ctrl->dma_wait_queued)
  7006. continue;
  7007. flush_workqueue(display->dma_cmd_workq);
  7008. cancel_work_sync(&ctrl->ctrl->dma_cmd_wait);
  7009. ctrl->ctrl->dma_wait_queued = false;
  7010. }
  7011. dsi_display_cmd_engine_disable(display);
  7012. dsi_display_clk_ctrl(display->dsi_clk_handle,
  7013. DSI_ALL_CLKS, DSI_CLK_OFF);
  7014. }
  7015. rc = dsi_display_ctrl_host_disable(display);
  7016. if (rc)
  7017. DSI_ERR("[%s] failed to disable DSI host, rc=%d\n",
  7018. display->name, rc);
  7019. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  7020. DSI_LINK_CLK, DSI_CLK_OFF);
  7021. if (rc)
  7022. DSI_ERR("[%s] failed to disable Link clocks, rc=%d\n",
  7023. display->name, rc);
  7024. rc = dsi_display_ctrl_deinit(display);
  7025. if (rc)
  7026. DSI_ERR("[%s] failed to deinit controller, rc=%d\n",
  7027. display->name, rc);
  7028. if (!display->panel->ulps_suspend_enabled) {
  7029. rc = dsi_display_phy_disable(display);
  7030. if (rc)
  7031. DSI_ERR("[%s] failed to disable DSI PHY, rc=%d\n",
  7032. display->name, rc);
  7033. }
  7034. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  7035. DSI_CORE_CLK, DSI_CLK_OFF);
  7036. if (rc)
  7037. DSI_ERR("[%s] failed to disable DSI clocks, rc=%d\n",
  7038. display->name, rc);
  7039. /* destrory dsi isr set up */
  7040. dsi_display_ctrl_isr_configure(display, false);
  7041. if (!display->poms_pending && !is_skip_op_required(display)) {
  7042. rc = dsi_panel_post_unprepare(display->panel);
  7043. if (rc)
  7044. DSI_ERR("[%s] panel post-unprepare failed, rc=%d\n",
  7045. display->name, rc);
  7046. }
  7047. mutex_unlock(&display->display_lock);
  7048. /* Free up DSI ERROR event callback */
  7049. dsi_display_unregister_error_handler(display);
  7050. SDE_EVT32(SDE_EVTLOG_FUNC_EXIT);
  7051. return rc;
  7052. }
  7053. void __init dsi_display_register(void)
  7054. {
  7055. dsi_phy_drv_register();
  7056. dsi_ctrl_drv_register();
  7057. dsi_display_parse_boot_display_selection();
  7058. platform_driver_register(&dsi_display_driver);
  7059. }
  7060. void __exit dsi_display_unregister(void)
  7061. {
  7062. platform_driver_unregister(&dsi_display_driver);
  7063. dsi_ctrl_drv_unregister();
  7064. dsi_phy_drv_unregister();
  7065. }
  7066. module_param_string(dsi_display0, dsi_display_primary, MAX_CMDLINE_PARAM_LEN,
  7067. 0600);
  7068. MODULE_PARM_DESC(dsi_display0,
  7069. "msm_drm.dsi_display0=<display node>:<configX> where <display node> is 'primary dsi display node name' and <configX> where x represents index in the topology list");
  7070. module_param_string(dsi_display1, dsi_display_secondary, MAX_CMDLINE_PARAM_LEN,
  7071. 0600);
  7072. MODULE_PARM_DESC(dsi_display1,
  7073. "msm_drm.dsi_display1=<display node>:<configX> where <display node> is 'secondary dsi display node name' and <configX> where x represents index in the topology list");