dsi_display.c 214 KB

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