dsi_display.c 223 KB

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