dsi_display.c 214 KB

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