dsi_display.c 189 KB

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