dsi_display.c 218 KB

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