dsi_display.c 214 KB

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