dsi_display.c 217 KB

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