dsi_display.c 224 KB

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