dsi_display.c 217 KB

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