dsi_display.c 176 KB

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