dsi_display.c 217 KB

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