dsi_display.c 210 KB

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