dsi_display.c 207 KB

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