dsi_display.c 219 KB

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