dsi_display.c 192 KB

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