dsi_display.c 179 KB

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