dsi_display.c 210 KB

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