dsi_display.c 209 KB

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