dsi_display.c 216 KB

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