dsi_display.c 222 KB

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