dsi_display.c 217 KB

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