dsi_display.c 196 KB

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