dsi_display.c 169 KB

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