dsi_display.c 167 KB

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