dsi_display.c 199 KB

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