dsi_display.c 228 KB

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