dsi_display.c 226 KB

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