dsi_display.c 218 KB

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