dsi_display.c 211 KB

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