dsi_display.c 183 KB

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