dsi_display.c 209 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486
  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. int dsi_display_phy_pll_toggle(void *priv, bool prepare)
  2211. {
  2212. int rc = 0;
  2213. struct dsi_display *display = priv;
  2214. struct dsi_display_ctrl *m_ctrl;
  2215. if (!display) {
  2216. DSI_ERR("invalid arguments\n");
  2217. return -EINVAL;
  2218. }
  2219. m_ctrl = &display->ctrl[display->clk_master_idx];
  2220. if (!m_ctrl->phy) {
  2221. DSI_ERR("[%s] PHY not found\n", display->name);
  2222. return -EINVAL;
  2223. }
  2224. rc = dsi_phy_pll_toggle(m_ctrl->phy, prepare);
  2225. return rc;
  2226. }
  2227. int dsi_display_phy_configure(void *priv, bool commit)
  2228. {
  2229. int rc = 0;
  2230. struct dsi_display *display = priv;
  2231. struct dsi_display_ctrl *m_ctrl;
  2232. struct dsi_pll_resource *pll_res;
  2233. struct dsi_ctrl *ctrl;
  2234. if (!display) {
  2235. DSI_ERR("invalid arguments\n");
  2236. return -EINVAL;
  2237. }
  2238. m_ctrl = &display->ctrl[display->clk_master_idx];
  2239. if ((!m_ctrl->phy) || (!m_ctrl->ctrl)) {
  2240. DSI_ERR("[%s] PHY not found\n", display->name);
  2241. return -EINVAL;
  2242. }
  2243. pll_res = m_ctrl->phy->pll;
  2244. if (!pll_res) {
  2245. DSI_ERR("[%s] PLL res not found\n", display->name);
  2246. return -EINVAL;
  2247. }
  2248. ctrl = m_ctrl->ctrl;
  2249. pll_res->byteclk_rate = ctrl->clk_freq.byte_clk_rate;
  2250. pll_res->pclk_rate = ctrl->clk_freq.pix_clk_rate;
  2251. rc = dsi_phy_configure(m_ctrl->phy, commit);
  2252. return rc;
  2253. }
  2254. static int dsi_display_set_clk_src(struct dsi_display *display)
  2255. {
  2256. int rc = 0;
  2257. int i;
  2258. struct dsi_display_ctrl *m_ctrl, *ctrl;
  2259. /*
  2260. * In case of split DSI usecases, the clock for master controller should
  2261. * be enabled before the other controller. Master controller in the
  2262. * clock context refers to the controller that sources the clock.
  2263. */
  2264. m_ctrl = &display->ctrl[display->clk_master_idx];
  2265. rc = dsi_ctrl_set_clock_source(m_ctrl->ctrl,
  2266. &display->clock_info.pll_clks);
  2267. if (rc) {
  2268. DSI_ERR("[%s] failed to set source clocks for master, rc=%d\n",
  2269. display->name, rc);
  2270. return rc;
  2271. }
  2272. /* Turn on rest of the controllers */
  2273. display_for_each_ctrl(i, display) {
  2274. ctrl = &display->ctrl[i];
  2275. if (!ctrl->ctrl || (ctrl == m_ctrl))
  2276. continue;
  2277. rc = dsi_ctrl_set_clock_source(ctrl->ctrl,
  2278. &display->clock_info.pll_clks);
  2279. if (rc) {
  2280. DSI_ERR("[%s] failed to set source clocks, rc=%d\n",
  2281. display->name, rc);
  2282. return rc;
  2283. }
  2284. }
  2285. return 0;
  2286. }
  2287. static int dsi_display_phy_reset_config(struct dsi_display *display,
  2288. bool enable)
  2289. {
  2290. int rc = 0;
  2291. int i;
  2292. struct dsi_display_ctrl *ctrl;
  2293. display_for_each_ctrl(i, display) {
  2294. ctrl = &display->ctrl[i];
  2295. rc = dsi_ctrl_phy_reset_config(ctrl->ctrl, enable);
  2296. if (rc) {
  2297. DSI_ERR("[%s] failed to %s phy reset, rc=%d\n",
  2298. display->name, enable ? "mask" : "unmask", rc);
  2299. return rc;
  2300. }
  2301. }
  2302. return 0;
  2303. }
  2304. static void dsi_display_toggle_resync_fifo(struct dsi_display *display)
  2305. {
  2306. struct dsi_display_ctrl *ctrl;
  2307. int i;
  2308. if (!display)
  2309. return;
  2310. display_for_each_ctrl(i, display) {
  2311. ctrl = &display->ctrl[i];
  2312. dsi_phy_toggle_resync_fifo(ctrl->phy);
  2313. }
  2314. /*
  2315. * After retime buffer synchronization we need to turn of clk_en_sel
  2316. * bit on each phy. Avoid this for Cphy.
  2317. */
  2318. if (display->panel->host_config.phy_type == DSI_PHY_TYPE_CPHY)
  2319. return;
  2320. display_for_each_ctrl(i, display) {
  2321. ctrl = &display->ctrl[i];
  2322. dsi_phy_reset_clk_en_sel(ctrl->phy);
  2323. }
  2324. }
  2325. static int dsi_display_ctrl_update(struct dsi_display *display)
  2326. {
  2327. int rc = 0;
  2328. int i;
  2329. struct dsi_display_ctrl *ctrl;
  2330. display_for_each_ctrl(i, display) {
  2331. ctrl = &display->ctrl[i];
  2332. rc = dsi_ctrl_host_timing_update(ctrl->ctrl);
  2333. if (rc) {
  2334. DSI_ERR("[%s] failed to update host_%d, rc=%d\n",
  2335. display->name, i, rc);
  2336. goto error_host_deinit;
  2337. }
  2338. }
  2339. return 0;
  2340. error_host_deinit:
  2341. for (i = i - 1; i >= 0; i--) {
  2342. ctrl = &display->ctrl[i];
  2343. (void)dsi_ctrl_host_deinit(ctrl->ctrl);
  2344. }
  2345. return rc;
  2346. }
  2347. static int dsi_display_ctrl_init(struct dsi_display *display)
  2348. {
  2349. int rc = 0;
  2350. int i;
  2351. struct dsi_display_ctrl *ctrl;
  2352. bool skip_op = is_skip_op_required(display);
  2353. /* when ULPS suspend feature is enabled, we will keep the lanes in
  2354. * ULPS during suspend state and clamp DSI phy. Hence while resuming
  2355. * we will programe DSI controller as part of core clock enable.
  2356. * After that we should not re-configure DSI controller again here for
  2357. * usecases where we are resuming from ulps suspend as it might put
  2358. * the HW in bad state.
  2359. */
  2360. if (!display->panel->ulps_suspend_enabled || !display->ulps_enabled) {
  2361. display_for_each_ctrl(i, display) {
  2362. ctrl = &display->ctrl[i];
  2363. rc = dsi_ctrl_host_init(ctrl->ctrl, skip_op);
  2364. if (rc) {
  2365. DSI_ERR(
  2366. "[%s] failed to init host_%d, skip_op=%d, rc=%d\n",
  2367. display->name, i, skip_op, rc);
  2368. goto error_host_deinit;
  2369. }
  2370. }
  2371. } else {
  2372. display_for_each_ctrl(i, display) {
  2373. ctrl = &display->ctrl[i];
  2374. rc = dsi_ctrl_update_host_state(ctrl->ctrl,
  2375. DSI_CTRL_OP_HOST_INIT,
  2376. true);
  2377. if (rc)
  2378. DSI_DEBUG("host init update failed rc=%d\n",
  2379. rc);
  2380. }
  2381. }
  2382. return rc;
  2383. error_host_deinit:
  2384. for (i = i - 1; i >= 0; i--) {
  2385. ctrl = &display->ctrl[i];
  2386. (void)dsi_ctrl_host_deinit(ctrl->ctrl);
  2387. }
  2388. return rc;
  2389. }
  2390. static int dsi_display_ctrl_deinit(struct dsi_display *display)
  2391. {
  2392. int rc = 0;
  2393. int i;
  2394. struct dsi_display_ctrl *ctrl;
  2395. display_for_each_ctrl(i, display) {
  2396. ctrl = &display->ctrl[i];
  2397. rc = dsi_ctrl_host_deinit(ctrl->ctrl);
  2398. if (rc) {
  2399. DSI_ERR("[%s] failed to deinit host_%d, rc=%d\n",
  2400. display->name, i, rc);
  2401. }
  2402. }
  2403. return rc;
  2404. }
  2405. static int dsi_display_ctrl_host_enable(struct dsi_display *display)
  2406. {
  2407. int rc = 0;
  2408. int i;
  2409. struct dsi_display_ctrl *m_ctrl, *ctrl;
  2410. bool skip_op = is_skip_op_required(display);
  2411. m_ctrl = &display->ctrl[display->cmd_master_idx];
  2412. rc = dsi_ctrl_set_host_engine_state(m_ctrl->ctrl,
  2413. DSI_CTRL_ENGINE_ON, skip_op);
  2414. if (rc) {
  2415. DSI_ERR("[%s]enable host engine failed, skip_op:%d rc:%d\n",
  2416. display->name, skip_op, rc);
  2417. goto error;
  2418. }
  2419. display_for_each_ctrl(i, display) {
  2420. ctrl = &display->ctrl[i];
  2421. if (!ctrl->ctrl || (ctrl == m_ctrl))
  2422. continue;
  2423. rc = dsi_ctrl_set_host_engine_state(ctrl->ctrl,
  2424. DSI_CTRL_ENGINE_ON, skip_op);
  2425. if (rc) {
  2426. DSI_ERR(
  2427. "[%s] enable host engine failed, skip_op:%d rc:%d\n",
  2428. display->name, skip_op, rc);
  2429. goto error_disable_master;
  2430. }
  2431. }
  2432. return rc;
  2433. error_disable_master:
  2434. (void)dsi_ctrl_set_host_engine_state(m_ctrl->ctrl,
  2435. DSI_CTRL_ENGINE_OFF, skip_op);
  2436. error:
  2437. return rc;
  2438. }
  2439. static int dsi_display_ctrl_host_disable(struct dsi_display *display)
  2440. {
  2441. int rc = 0;
  2442. int i;
  2443. struct dsi_display_ctrl *m_ctrl, *ctrl;
  2444. bool skip_op = is_skip_op_required(display);
  2445. m_ctrl = &display->ctrl[display->cmd_master_idx];
  2446. /*
  2447. * For platforms where ULPS is controlled by DSI controller block,
  2448. * do not disable dsi controller block if lanes are to be
  2449. * kept in ULPS during suspend. So just update the SW state
  2450. * and return early.
  2451. */
  2452. if (display->panel->ulps_suspend_enabled &&
  2453. !m_ctrl->phy->hw.ops.ulps_ops.ulps_request) {
  2454. display_for_each_ctrl(i, display) {
  2455. ctrl = &display->ctrl[i];
  2456. rc = dsi_ctrl_update_host_state(ctrl->ctrl,
  2457. DSI_CTRL_OP_HOST_ENGINE,
  2458. false);
  2459. if (rc)
  2460. DSI_DEBUG("host state update failed %d\n", rc);
  2461. }
  2462. return rc;
  2463. }
  2464. display_for_each_ctrl(i, display) {
  2465. ctrl = &display->ctrl[i];
  2466. if (!ctrl->ctrl || (ctrl == m_ctrl))
  2467. continue;
  2468. rc = dsi_ctrl_set_host_engine_state(ctrl->ctrl,
  2469. DSI_CTRL_ENGINE_OFF, skip_op);
  2470. if (rc)
  2471. DSI_ERR(
  2472. "[%s] disable host engine failed, skip_op:%d rc:%d\n",
  2473. display->name, skip_op, rc);
  2474. }
  2475. rc = dsi_ctrl_set_host_engine_state(m_ctrl->ctrl,
  2476. DSI_CTRL_ENGINE_OFF, skip_op);
  2477. if (rc) {
  2478. DSI_ERR("[%s] disable mhost engine failed, skip_op:%d rc:%d\n",
  2479. display->name, skip_op, rc);
  2480. goto error;
  2481. }
  2482. error:
  2483. return rc;
  2484. }
  2485. static int dsi_display_vid_engine_enable(struct dsi_display *display)
  2486. {
  2487. int rc = 0;
  2488. int i;
  2489. struct dsi_display_ctrl *m_ctrl, *ctrl;
  2490. bool skip_op = is_skip_op_required(display);
  2491. m_ctrl = &display->ctrl[display->video_master_idx];
  2492. rc = dsi_ctrl_set_vid_engine_state(m_ctrl->ctrl,
  2493. DSI_CTRL_ENGINE_ON, skip_op);
  2494. if (rc) {
  2495. DSI_ERR("[%s] enable mvid engine failed, skip_op:%d rc:%d\n",
  2496. display->name, skip_op, rc);
  2497. goto error;
  2498. }
  2499. display_for_each_ctrl(i, display) {
  2500. ctrl = &display->ctrl[i];
  2501. if (!ctrl->ctrl || (ctrl == m_ctrl))
  2502. continue;
  2503. rc = dsi_ctrl_set_vid_engine_state(ctrl->ctrl,
  2504. DSI_CTRL_ENGINE_ON, skip_op);
  2505. if (rc) {
  2506. DSI_ERR(
  2507. "[%s] enable vid engine failed, skip_op:%d rc:%d\n",
  2508. display->name, skip_op, rc);
  2509. goto error_disable_master;
  2510. }
  2511. }
  2512. return rc;
  2513. error_disable_master:
  2514. (void)dsi_ctrl_set_vid_engine_state(m_ctrl->ctrl,
  2515. DSI_CTRL_ENGINE_OFF, skip_op);
  2516. error:
  2517. return rc;
  2518. }
  2519. static int dsi_display_vid_engine_disable(struct dsi_display *display)
  2520. {
  2521. int rc = 0;
  2522. int i;
  2523. struct dsi_display_ctrl *m_ctrl, *ctrl;
  2524. bool skip_op = is_skip_op_required(display);
  2525. m_ctrl = &display->ctrl[display->video_master_idx];
  2526. display_for_each_ctrl(i, display) {
  2527. ctrl = &display->ctrl[i];
  2528. if (!ctrl->ctrl || (ctrl == m_ctrl))
  2529. continue;
  2530. rc = dsi_ctrl_set_vid_engine_state(ctrl->ctrl,
  2531. DSI_CTRL_ENGINE_OFF, skip_op);
  2532. if (rc)
  2533. DSI_ERR(
  2534. "[%s] disable vid engine failed, skip_op:%d rc:%d\n",
  2535. display->name, skip_op, rc);
  2536. }
  2537. rc = dsi_ctrl_set_vid_engine_state(m_ctrl->ctrl,
  2538. DSI_CTRL_ENGINE_OFF, skip_op);
  2539. if (rc)
  2540. DSI_ERR("[%s] disable mvid engine failed, skip_op:%d rc:%d\n",
  2541. display->name, skip_op, rc);
  2542. return rc;
  2543. }
  2544. static int dsi_display_phy_enable(struct dsi_display *display)
  2545. {
  2546. int rc = 0;
  2547. int i;
  2548. struct dsi_display_ctrl *m_ctrl, *ctrl;
  2549. enum dsi_phy_pll_source m_src = DSI_PLL_SOURCE_STANDALONE;
  2550. bool skip_op = is_skip_op_required(display);
  2551. m_ctrl = &display->ctrl[display->clk_master_idx];
  2552. if (display->ctrl_count > 1)
  2553. m_src = DSI_PLL_SOURCE_NATIVE;
  2554. rc = dsi_phy_enable(m_ctrl->phy, &display->config,
  2555. m_src, true, skip_op);
  2556. if (rc) {
  2557. DSI_ERR("[%s] failed to enable DSI PHY, skip_op=%d rc=%d\n",
  2558. display->name, skip_op, rc);
  2559. goto error;
  2560. }
  2561. display_for_each_ctrl(i, display) {
  2562. ctrl = &display->ctrl[i];
  2563. if (!ctrl->ctrl || (ctrl == m_ctrl))
  2564. continue;
  2565. rc = dsi_phy_enable(ctrl->phy, &display->config,
  2566. DSI_PLL_SOURCE_NON_NATIVE, true, skip_op);
  2567. if (rc) {
  2568. DSI_ERR(
  2569. "[%s] failed to enable DSI PHY, skip_op: %d rc=%d\n",
  2570. display->name, skip_op, rc);
  2571. goto error_disable_master;
  2572. }
  2573. }
  2574. return rc;
  2575. error_disable_master:
  2576. (void)dsi_phy_disable(m_ctrl->phy, skip_op);
  2577. error:
  2578. return rc;
  2579. }
  2580. static int dsi_display_phy_disable(struct dsi_display *display)
  2581. {
  2582. int rc = 0;
  2583. int i;
  2584. struct dsi_display_ctrl *m_ctrl, *ctrl;
  2585. bool skip_op = is_skip_op_required(display);
  2586. m_ctrl = &display->ctrl[display->clk_master_idx];
  2587. display_for_each_ctrl(i, display) {
  2588. ctrl = &display->ctrl[i];
  2589. if (!ctrl->ctrl || (ctrl == m_ctrl))
  2590. continue;
  2591. rc = dsi_phy_disable(ctrl->phy, skip_op);
  2592. if (rc)
  2593. DSI_ERR(
  2594. "[%s] failed to disable DSI PHY, skip_op=%d rc=%d\n",
  2595. display->name, skip_op, rc);
  2596. }
  2597. rc = dsi_phy_disable(m_ctrl->phy, skip_op);
  2598. if (rc)
  2599. DSI_ERR("[%s] failed to disable DSI PHY, skip_op=%d rc=%d\n",
  2600. display->name, skip_op, rc);
  2601. return rc;
  2602. }
  2603. static int dsi_display_wake_up(struct dsi_display *display)
  2604. {
  2605. return 0;
  2606. }
  2607. static void dsi_display_mask_overflow(struct dsi_display *display, u32 flags,
  2608. bool enable)
  2609. {
  2610. struct dsi_display_ctrl *ctrl;
  2611. int i;
  2612. if (!(flags & DSI_CTRL_CMD_LAST_COMMAND))
  2613. return;
  2614. display_for_each_ctrl(i, display) {
  2615. ctrl = &display->ctrl[i];
  2616. if (!ctrl)
  2617. continue;
  2618. dsi_ctrl_mask_overflow(ctrl->ctrl, enable);
  2619. }
  2620. }
  2621. static int dsi_display_broadcast_cmd(struct dsi_display *display, struct dsi_cmd_desc *cmd)
  2622. {
  2623. int rc = 0;
  2624. struct dsi_display_ctrl *ctrl, *m_ctrl;
  2625. int i;
  2626. /*
  2627. * 1. Setup commands in FIFO
  2628. * 2. Trigger commands
  2629. */
  2630. m_ctrl = &display->ctrl[display->cmd_master_idx];
  2631. dsi_display_mask_overflow(display, cmd->ctrl_flags, true);
  2632. cmd->ctrl_flags |= DSI_CTRL_CMD_BROADCAST_MASTER;
  2633. rc = dsi_ctrl_cmd_transfer(m_ctrl->ctrl, cmd);
  2634. if (rc) {
  2635. DSI_ERR("[%s] cmd transfer failed on master,rc=%d\n",
  2636. display->name, rc);
  2637. goto error;
  2638. }
  2639. cmd->ctrl_flags &= ~DSI_CTRL_CMD_BROADCAST_MASTER;
  2640. display_for_each_ctrl(i, display) {
  2641. ctrl = &display->ctrl[i];
  2642. if (ctrl == m_ctrl)
  2643. continue;
  2644. rc = dsi_ctrl_cmd_transfer(ctrl->ctrl, cmd);
  2645. if (rc) {
  2646. DSI_ERR("[%s] cmd transfer failed, rc=%d\n",
  2647. display->name, rc);
  2648. goto error;
  2649. }
  2650. rc = dsi_ctrl_cmd_tx_trigger(ctrl->ctrl, cmd->ctrl_flags);
  2651. if (rc) {
  2652. DSI_ERR("[%s] cmd trigger failed, rc=%d\n",
  2653. display->name, rc);
  2654. goto error;
  2655. }
  2656. }
  2657. rc = dsi_ctrl_cmd_tx_trigger(m_ctrl->ctrl, cmd->ctrl_flags | DSI_CTRL_CMD_BROADCAST_MASTER);
  2658. if (rc) {
  2659. DSI_ERR("[%s] cmd trigger failed for master, rc=%d\n",
  2660. display->name, rc);
  2661. goto error;
  2662. }
  2663. error:
  2664. dsi_display_mask_overflow(display, cmd->ctrl_flags, false);
  2665. return rc;
  2666. }
  2667. static int dsi_display_phy_sw_reset(struct dsi_display *display)
  2668. {
  2669. int rc = 0;
  2670. int i;
  2671. struct dsi_display_ctrl *m_ctrl, *ctrl;
  2672. /*
  2673. * For continuous splash and trusted vm environment,
  2674. * ctrl states are updated separately and hence we do
  2675. * an early return
  2676. */
  2677. if (is_skip_op_required(display)) {
  2678. DSI_DEBUG(
  2679. "cont splash/trusted vm use case, phy sw reset not required\n");
  2680. return 0;
  2681. }
  2682. m_ctrl = &display->ctrl[display->cmd_master_idx];
  2683. rc = dsi_ctrl_phy_sw_reset(m_ctrl->ctrl);
  2684. if (rc) {
  2685. DSI_ERR("[%s] failed to reset phy, rc=%d\n", display->name, rc);
  2686. goto error;
  2687. }
  2688. display_for_each_ctrl(i, display) {
  2689. ctrl = &display->ctrl[i];
  2690. if (!ctrl->ctrl || (ctrl == m_ctrl))
  2691. continue;
  2692. rc = dsi_ctrl_phy_sw_reset(ctrl->ctrl);
  2693. if (rc) {
  2694. DSI_ERR("[%s] failed to reset phy, rc=%d\n",
  2695. display->name, rc);
  2696. goto error;
  2697. }
  2698. }
  2699. error:
  2700. return rc;
  2701. }
  2702. static int dsi_host_attach(struct mipi_dsi_host *host,
  2703. struct mipi_dsi_device *dsi)
  2704. {
  2705. return 0;
  2706. }
  2707. static int dsi_host_detach(struct mipi_dsi_host *host,
  2708. struct mipi_dsi_device *dsi)
  2709. {
  2710. return 0;
  2711. }
  2712. int dsi_host_transfer_sub(struct mipi_dsi_host *host, struct dsi_cmd_desc *cmd)
  2713. {
  2714. struct dsi_display *display;
  2715. int rc = 0, ret = 0;
  2716. if (!host || !cmd) {
  2717. DSI_ERR("Invalid params\n");
  2718. return 0;
  2719. }
  2720. display = to_dsi_display(host);
  2721. /* Avoid sending DCS commands when ESD recovery is pending */
  2722. if (atomic_read(&display->panel->esd_recovery_pending)) {
  2723. DSI_DEBUG("ESD recovery pending\n");
  2724. return 0;
  2725. }
  2726. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  2727. DSI_ALL_CLKS, DSI_CLK_ON);
  2728. if (rc) {
  2729. DSI_ERR("[%s] failed to enable all DSI clocks, rc=%d\n",
  2730. display->name, rc);
  2731. goto error;
  2732. }
  2733. rc = dsi_display_wake_up(display);
  2734. if (rc) {
  2735. DSI_ERR("[%s] failed to wake up display, rc=%d\n",
  2736. display->name, rc);
  2737. goto error_disable_clks;
  2738. }
  2739. rc = dsi_display_cmd_engine_enable(display);
  2740. if (rc) {
  2741. DSI_ERR("[%s] failed to enable cmd engine, rc=%d\n",
  2742. display->name, rc);
  2743. goto error_disable_clks;
  2744. }
  2745. if (display->tx_cmd_buf == NULL) {
  2746. rc = dsi_host_alloc_cmd_tx_buffer(display);
  2747. if (rc) {
  2748. DSI_ERR("failed to allocate cmd tx buffer memory\n");
  2749. goto error_disable_cmd_engine;
  2750. }
  2751. }
  2752. dsi_display_set_cmd_tx_ctrl_flags(display, cmd);
  2753. if (cmd->ctrl_flags & DSI_CTRL_CMD_BROADCAST) {
  2754. rc = dsi_display_broadcast_cmd(display, cmd);
  2755. if (rc) {
  2756. DSI_ERR("[%s] cmd broadcast failed, rc=%d\n", display->name, rc);
  2757. goto error_disable_cmd_engine;
  2758. }
  2759. } else {
  2760. int idx = cmd->ctrl;
  2761. rc = dsi_ctrl_cmd_transfer(display->ctrl[idx].ctrl, cmd);
  2762. if (rc) {
  2763. DSI_ERR("[%s] cmd transfer failed, rc=%d\n",
  2764. display->name, rc);
  2765. goto error_disable_cmd_engine;
  2766. }
  2767. }
  2768. error_disable_cmd_engine:
  2769. ret = dsi_display_cmd_engine_disable(display);
  2770. if (ret) {
  2771. DSI_ERR("[%s]failed to disable DSI cmd engine, rc=%d\n",
  2772. display->name, ret);
  2773. }
  2774. error_disable_clks:
  2775. ret = dsi_display_clk_ctrl(display->dsi_clk_handle,
  2776. DSI_ALL_CLKS, DSI_CLK_OFF);
  2777. if (ret) {
  2778. DSI_ERR("[%s] failed to disable all DSI clocks, rc=%d\n",
  2779. display->name, ret);
  2780. }
  2781. error:
  2782. return rc;
  2783. }
  2784. static ssize_t dsi_host_transfer(struct mipi_dsi_host *host, const struct mipi_dsi_msg *msg)
  2785. {
  2786. int rc = 0;
  2787. struct dsi_cmd_desc cmd;
  2788. if (!msg) {
  2789. DSI_ERR("Invalid params\n");
  2790. return 0;
  2791. }
  2792. memcpy(&cmd.msg, msg, sizeof(*msg));
  2793. cmd.ctrl = 0;
  2794. cmd.post_wait_ms = 0;
  2795. cmd.ctrl_flags = 0;
  2796. rc = dsi_host_transfer_sub(host, &cmd);
  2797. return rc;
  2798. }
  2799. static struct mipi_dsi_host_ops dsi_host_ops = {
  2800. .attach = dsi_host_attach,
  2801. .detach = dsi_host_detach,
  2802. .transfer = dsi_host_transfer,
  2803. };
  2804. static int dsi_display_mipi_host_init(struct dsi_display *display)
  2805. {
  2806. int rc = 0;
  2807. struct mipi_dsi_host *host = &display->host;
  2808. host->dev = &display->pdev->dev;
  2809. host->ops = &dsi_host_ops;
  2810. rc = mipi_dsi_host_register(host);
  2811. if (rc) {
  2812. DSI_ERR("[%s] failed to register mipi dsi host, rc=%d\n",
  2813. display->name, rc);
  2814. goto error;
  2815. }
  2816. error:
  2817. return rc;
  2818. }
  2819. static int dsi_display_mipi_host_deinit(struct dsi_display *display)
  2820. {
  2821. int rc = 0;
  2822. struct mipi_dsi_host *host = &display->host;
  2823. mipi_dsi_host_unregister(host);
  2824. host->dev = NULL;
  2825. host->ops = NULL;
  2826. return rc;
  2827. }
  2828. static bool dsi_display_check_prefix(const char *clk_prefix,
  2829. const char *clk_name)
  2830. {
  2831. return !!strnstr(clk_name, clk_prefix, strlen(clk_name));
  2832. }
  2833. static int dsi_display_get_clocks_count(struct dsi_display *display,
  2834. char *dsi_clk_name)
  2835. {
  2836. if (display->fw)
  2837. return dsi_parser_count_strings(display->parser_node,
  2838. dsi_clk_name);
  2839. else
  2840. return of_property_count_strings(display->panel_node,
  2841. dsi_clk_name);
  2842. }
  2843. static void dsi_display_get_clock_name(struct dsi_display *display,
  2844. char *dsi_clk_name, int index,
  2845. const char **clk_name)
  2846. {
  2847. if (display->fw)
  2848. dsi_parser_read_string_index(display->parser_node,
  2849. dsi_clk_name, index, clk_name);
  2850. else
  2851. of_property_read_string_index(display->panel_node,
  2852. dsi_clk_name, index, clk_name);
  2853. }
  2854. static int dsi_display_clocks_init(struct dsi_display *display)
  2855. {
  2856. int i, rc = 0, num_clk = 0;
  2857. const char *clk_name;
  2858. const char *pll_byte = "pll_byte", *pll_dsi = "pll_dsi";
  2859. struct clk *dsi_clk;
  2860. struct dsi_clk_link_set *pll = &display->clock_info.pll_clks;
  2861. char *dsi_clock_name;
  2862. if (!strcmp(display->display_type, "primary"))
  2863. dsi_clock_name = "qcom,dsi-select-clocks";
  2864. else
  2865. dsi_clock_name = "qcom,dsi-select-sec-clocks";
  2866. num_clk = dsi_display_get_clocks_count(display, dsi_clock_name);
  2867. for (i = 0; i < num_clk; i++) {
  2868. dsi_display_get_clock_name(display, dsi_clock_name, i,
  2869. &clk_name);
  2870. DSI_DEBUG("clock name:%s\n", clk_name);
  2871. dsi_clk = devm_clk_get(&display->pdev->dev, clk_name);
  2872. if (IS_ERR_OR_NULL(dsi_clk)) {
  2873. rc = PTR_ERR(dsi_clk);
  2874. DSI_ERR("failed to get %s, rc=%d\n", clk_name, rc);
  2875. if (dsi_display_check_prefix(pll_byte, clk_name)) {
  2876. pll->byte_clk = NULL;
  2877. goto error;
  2878. }
  2879. if (dsi_display_check_prefix(pll_dsi, clk_name)) {
  2880. pll->pixel_clk = NULL;
  2881. goto error;
  2882. }
  2883. }
  2884. if (dsi_display_check_prefix(pll_byte, clk_name)) {
  2885. pll->byte_clk = dsi_clk;
  2886. continue;
  2887. }
  2888. if (dsi_display_check_prefix(pll_dsi, clk_name)) {
  2889. pll->pixel_clk = dsi_clk;
  2890. continue;
  2891. }
  2892. }
  2893. return 0;
  2894. error:
  2895. return rc;
  2896. }
  2897. static int dsi_display_clk_ctrl_cb(void *priv,
  2898. struct dsi_clk_ctrl_info clk_state_info)
  2899. {
  2900. int rc = 0;
  2901. struct dsi_display *display = NULL;
  2902. void *clk_handle = NULL;
  2903. if (!priv) {
  2904. DSI_ERR("Invalid params\n");
  2905. return -EINVAL;
  2906. }
  2907. display = priv;
  2908. if (clk_state_info.client == DSI_CLK_REQ_MDP_CLIENT) {
  2909. clk_handle = display->mdp_clk_handle;
  2910. } else if (clk_state_info.client == DSI_CLK_REQ_DSI_CLIENT) {
  2911. clk_handle = display->dsi_clk_handle;
  2912. } else {
  2913. DSI_ERR("invalid clk handle, return error\n");
  2914. return -EINVAL;
  2915. }
  2916. /*
  2917. * TODO: Wait for CMD_MDP_DONE interrupt if MDP client tries
  2918. * to turn off DSI clocks.
  2919. */
  2920. rc = dsi_display_clk_ctrl(clk_handle,
  2921. clk_state_info.clk_type, clk_state_info.clk_state);
  2922. if (rc) {
  2923. DSI_ERR("[%s] failed to %d DSI %d clocks, rc=%d\n",
  2924. display->name, clk_state_info.clk_state,
  2925. clk_state_info.clk_type, rc);
  2926. return rc;
  2927. }
  2928. return 0;
  2929. }
  2930. static void dsi_display_ctrl_isr_configure(struct dsi_display *display, bool en)
  2931. {
  2932. int i;
  2933. struct dsi_display_ctrl *ctrl;
  2934. if (!display)
  2935. return;
  2936. display_for_each_ctrl(i, display) {
  2937. ctrl = &display->ctrl[i];
  2938. if (!ctrl)
  2939. continue;
  2940. dsi_ctrl_isr_configure(ctrl->ctrl, en);
  2941. }
  2942. }
  2943. int dsi_pre_clkoff_cb(void *priv,
  2944. enum dsi_clk_type clk,
  2945. enum dsi_lclk_type l_type,
  2946. enum dsi_clk_state new_state)
  2947. {
  2948. int rc = 0, i;
  2949. struct dsi_display *display = priv;
  2950. struct dsi_display_ctrl *ctrl;
  2951. /*
  2952. * If Idle Power Collapse occurs immediately after a CMD
  2953. * transfer with an asynchronous wait for DMA done, ensure
  2954. * that the work queued is scheduled and completed before turning
  2955. * off the clocks and disabling interrupts to validate the command
  2956. * transfer.
  2957. */
  2958. display_for_each_ctrl(i, display) {
  2959. ctrl = &display->ctrl[i];
  2960. if (!ctrl->ctrl || !ctrl->ctrl->dma_wait_queued)
  2961. continue;
  2962. flush_workqueue(display->dma_cmd_workq);
  2963. cancel_work_sync(&ctrl->ctrl->dma_cmd_wait);
  2964. ctrl->ctrl->dma_wait_queued = false;
  2965. }
  2966. if ((clk & DSI_LINK_CLK) && (new_state == DSI_CLK_OFF) &&
  2967. (l_type & DSI_LINK_LP_CLK)) {
  2968. /*
  2969. * If continuous clock is enabled then disable it
  2970. * before entering into ULPS Mode.
  2971. */
  2972. if (display->panel->host_config.force_hs_clk_lane)
  2973. _dsi_display_continuous_clk_ctrl(display, false);
  2974. /*
  2975. * If ULPS feature is enabled, enter ULPS first.
  2976. * However, when blanking the panel, we should enter ULPS
  2977. * only if ULPS during suspend feature is enabled.
  2978. */
  2979. if (!dsi_panel_initialized(display->panel)) {
  2980. if (display->panel->ulps_suspend_enabled)
  2981. rc = dsi_display_set_ulps(display, true);
  2982. } else if (dsi_panel_ulps_feature_enabled(display->panel)) {
  2983. rc = dsi_display_set_ulps(display, true);
  2984. }
  2985. if (rc)
  2986. DSI_ERR("%s: failed enable ulps, rc = %d\n",
  2987. __func__, rc);
  2988. }
  2989. if ((clk & DSI_LINK_CLK) && (new_state == DSI_CLK_OFF) &&
  2990. (l_type & DSI_LINK_HS_CLK)) {
  2991. /*
  2992. * PHY clock gating should be disabled before the PLL and the
  2993. * branch clocks are turned off. Otherwise, it is possible that
  2994. * the clock RCGs may not be turned off correctly resulting
  2995. * in clock warnings.
  2996. */
  2997. rc = dsi_display_config_clk_gating(display, false);
  2998. if (rc)
  2999. DSI_ERR("[%s] failed to disable clk gating, rc=%d\n",
  3000. display->name, rc);
  3001. }
  3002. if ((clk & DSI_CORE_CLK) && (new_state == DSI_CLK_OFF)) {
  3003. /*
  3004. * Enable DSI clamps only if entering idle power collapse or
  3005. * when ULPS during suspend is enabled..
  3006. */
  3007. if (dsi_panel_initialized(display->panel) ||
  3008. display->panel->ulps_suspend_enabled) {
  3009. dsi_display_phy_idle_off(display);
  3010. rc = dsi_display_set_clamp(display, true);
  3011. if (rc)
  3012. DSI_ERR("%s: Failed to enable dsi clamps. rc=%d\n",
  3013. __func__, rc);
  3014. rc = dsi_display_phy_reset_config(display, false);
  3015. if (rc)
  3016. DSI_ERR("%s: Failed to reset phy, rc=%d\n",
  3017. __func__, rc);
  3018. } else {
  3019. /* Make sure that controller is not in ULPS state when
  3020. * the DSI link is not active.
  3021. */
  3022. rc = dsi_display_set_ulps(display, false);
  3023. if (rc)
  3024. DSI_ERR("%s: failed to disable ulps. rc=%d\n",
  3025. __func__, rc);
  3026. }
  3027. /* dsi will not be able to serve irqs from here on */
  3028. dsi_display_ctrl_irq_update(display, false);
  3029. /* cache the MISR values */
  3030. display_for_each_ctrl(i, display) {
  3031. ctrl = &display->ctrl[i];
  3032. if (!ctrl->ctrl)
  3033. continue;
  3034. dsi_ctrl_cache_misr(ctrl->ctrl);
  3035. }
  3036. }
  3037. return rc;
  3038. }
  3039. int dsi_post_clkon_cb(void *priv,
  3040. enum dsi_clk_type clk,
  3041. enum dsi_lclk_type l_type,
  3042. enum dsi_clk_state curr_state)
  3043. {
  3044. int rc = 0;
  3045. struct dsi_display *display = priv;
  3046. bool mmss_clamp = false;
  3047. if ((clk & DSI_LINK_CLK) && (l_type & DSI_LINK_LP_CLK)) {
  3048. mmss_clamp = display->clamp_enabled;
  3049. /*
  3050. * controller setup is needed if coming out of idle
  3051. * power collapse with clamps enabled.
  3052. */
  3053. if (mmss_clamp)
  3054. dsi_display_ctrl_setup(display);
  3055. /*
  3056. * Phy setup is needed if coming out of idle
  3057. * power collapse with clamps enabled.
  3058. */
  3059. if (display->phy_idle_power_off || mmss_clamp)
  3060. dsi_display_phy_idle_on(display, mmss_clamp);
  3061. if (display->ulps_enabled && mmss_clamp) {
  3062. /*
  3063. * ULPS Entry Request. This is needed if the lanes were
  3064. * in ULPS prior to power collapse, since after
  3065. * power collapse and reset, the DSI controller resets
  3066. * back to idle state and not ULPS. This ulps entry
  3067. * request will transition the state of the DSI
  3068. * controller to ULPS which will match the state of the
  3069. * DSI phy. This needs to be done prior to disabling
  3070. * the DSI clamps.
  3071. *
  3072. * Also, reset the ulps flag so that ulps_config
  3073. * function would reconfigure the controller state to
  3074. * ULPS.
  3075. */
  3076. display->ulps_enabled = false;
  3077. rc = dsi_display_set_ulps(display, true);
  3078. if (rc) {
  3079. DSI_ERR("%s: Failed to enter ULPS. rc=%d\n",
  3080. __func__, rc);
  3081. goto error;
  3082. }
  3083. }
  3084. rc = dsi_display_phy_reset_config(display, true);
  3085. if (rc) {
  3086. DSI_ERR("%s: Failed to reset phy, rc=%d\n",
  3087. __func__, rc);
  3088. goto error;
  3089. }
  3090. rc = dsi_display_set_clamp(display, false);
  3091. if (rc) {
  3092. DSI_ERR("%s: Failed to disable dsi clamps. rc=%d\n",
  3093. __func__, rc);
  3094. goto error;
  3095. }
  3096. }
  3097. if ((clk & DSI_LINK_CLK) && (l_type & DSI_LINK_HS_CLK)) {
  3098. /*
  3099. * Toggle the resync FIFO everytime clock changes, except
  3100. * when cont-splash screen transition is going on.
  3101. * Toggling resync FIFO during cont splash transition
  3102. * can lead to blinks on the display.
  3103. */
  3104. if (!display->is_cont_splash_enabled)
  3105. dsi_display_toggle_resync_fifo(display);
  3106. if (display->ulps_enabled) {
  3107. rc = dsi_display_set_ulps(display, false);
  3108. if (rc) {
  3109. DSI_ERR("%s: failed to disable ulps, rc= %d\n",
  3110. __func__, rc);
  3111. goto error;
  3112. }
  3113. }
  3114. if (display->panel->host_config.force_hs_clk_lane)
  3115. _dsi_display_continuous_clk_ctrl(display, true);
  3116. rc = dsi_display_config_clk_gating(display, true);
  3117. if (rc) {
  3118. DSI_ERR("[%s] failed to enable clk gating %d\n",
  3119. display->name, rc);
  3120. goto error;
  3121. }
  3122. }
  3123. /* enable dsi to serve irqs */
  3124. if (clk & DSI_CORE_CLK)
  3125. dsi_display_ctrl_irq_update(display, true);
  3126. error:
  3127. return rc;
  3128. }
  3129. int dsi_post_clkoff_cb(void *priv,
  3130. enum dsi_clk_type clk_type,
  3131. enum dsi_lclk_type l_type,
  3132. enum dsi_clk_state curr_state)
  3133. {
  3134. int rc = 0;
  3135. struct dsi_display *display = priv;
  3136. if (!display) {
  3137. DSI_ERR("%s: Invalid arg\n", __func__);
  3138. return -EINVAL;
  3139. }
  3140. if ((clk_type & DSI_CORE_CLK) &&
  3141. (curr_state == DSI_CLK_OFF)) {
  3142. rc = dsi_display_phy_power_off(display);
  3143. if (rc)
  3144. DSI_ERR("[%s] failed to power off PHY, rc=%d\n",
  3145. display->name, rc);
  3146. rc = dsi_display_ctrl_power_off(display);
  3147. if (rc)
  3148. DSI_ERR("[%s] failed to power DSI vregs, rc=%d\n",
  3149. display->name, rc);
  3150. }
  3151. return rc;
  3152. }
  3153. int dsi_pre_clkon_cb(void *priv,
  3154. enum dsi_clk_type clk_type,
  3155. enum dsi_lclk_type l_type,
  3156. enum dsi_clk_state new_state)
  3157. {
  3158. int rc = 0;
  3159. struct dsi_display *display = priv;
  3160. if (!display) {
  3161. DSI_ERR("%s: invalid input\n", __func__);
  3162. return -EINVAL;
  3163. }
  3164. if ((clk_type & DSI_CORE_CLK) && (new_state == DSI_CLK_ON)) {
  3165. /*
  3166. * Enable DSI core power
  3167. * 1.> PANEL_PM are controlled as part of
  3168. * panel_power_ctrl. Needed not be handled here.
  3169. * 2.> CTRL_PM need to be enabled/disabled
  3170. * only during unblank/blank. Their state should
  3171. * not be changed during static screen.
  3172. */
  3173. DSI_DEBUG("updating power states for ctrl and phy\n");
  3174. rc = dsi_display_ctrl_power_on(display);
  3175. if (rc) {
  3176. DSI_ERR("[%s] failed to power on dsi controllers, rc=%d\n",
  3177. display->name, rc);
  3178. return rc;
  3179. }
  3180. rc = dsi_display_phy_power_on(display);
  3181. if (rc) {
  3182. DSI_ERR("[%s] failed to power on dsi phy, rc = %d\n",
  3183. display->name, rc);
  3184. return rc;
  3185. }
  3186. DSI_DEBUG("%s: Enable DSI core power\n", __func__);
  3187. }
  3188. return rc;
  3189. }
  3190. static void __set_lane_map_v2(u8 *lane_map_v2,
  3191. enum dsi_phy_data_lanes lane0,
  3192. enum dsi_phy_data_lanes lane1,
  3193. enum dsi_phy_data_lanes lane2,
  3194. enum dsi_phy_data_lanes lane3)
  3195. {
  3196. lane_map_v2[DSI_LOGICAL_LANE_0] = lane0;
  3197. lane_map_v2[DSI_LOGICAL_LANE_1] = lane1;
  3198. lane_map_v2[DSI_LOGICAL_LANE_2] = lane2;
  3199. lane_map_v2[DSI_LOGICAL_LANE_3] = lane3;
  3200. }
  3201. static int dsi_display_parse_lane_map(struct dsi_display *display)
  3202. {
  3203. int rc = 0, i = 0;
  3204. const char *data;
  3205. u8 temp[DSI_LANE_MAX - 1];
  3206. if (!display) {
  3207. DSI_ERR("invalid params\n");
  3208. return -EINVAL;
  3209. }
  3210. /* lane-map-v2 supersedes lane-map-v1 setting */
  3211. rc = of_property_read_u8_array(display->pdev->dev.of_node,
  3212. "qcom,lane-map-v2", temp, (DSI_LANE_MAX - 1));
  3213. if (!rc) {
  3214. for (i = DSI_LOGICAL_LANE_0; i < (DSI_LANE_MAX - 1); i++)
  3215. display->lane_map.lane_map_v2[i] = BIT(temp[i]);
  3216. return 0;
  3217. } else if (rc != EINVAL) {
  3218. DSI_DEBUG("Incorrect mapping, configure default\n");
  3219. goto set_default;
  3220. }
  3221. /* lane-map older version, for DSI controller version < 2.0 */
  3222. data = of_get_property(display->pdev->dev.of_node,
  3223. "qcom,lane-map", NULL);
  3224. if (!data)
  3225. goto set_default;
  3226. if (!strcmp(data, "lane_map_3012")) {
  3227. display->lane_map.lane_map_v1 = DSI_LANE_MAP_3012;
  3228. __set_lane_map_v2(display->lane_map.lane_map_v2,
  3229. DSI_PHYSICAL_LANE_1,
  3230. DSI_PHYSICAL_LANE_2,
  3231. DSI_PHYSICAL_LANE_3,
  3232. DSI_PHYSICAL_LANE_0);
  3233. } else if (!strcmp(data, "lane_map_2301")) {
  3234. display->lane_map.lane_map_v1 = DSI_LANE_MAP_2301;
  3235. __set_lane_map_v2(display->lane_map.lane_map_v2,
  3236. DSI_PHYSICAL_LANE_2,
  3237. DSI_PHYSICAL_LANE_3,
  3238. DSI_PHYSICAL_LANE_0,
  3239. DSI_PHYSICAL_LANE_1);
  3240. } else if (!strcmp(data, "lane_map_1230")) {
  3241. display->lane_map.lane_map_v1 = DSI_LANE_MAP_1230;
  3242. __set_lane_map_v2(display->lane_map.lane_map_v2,
  3243. DSI_PHYSICAL_LANE_3,
  3244. DSI_PHYSICAL_LANE_0,
  3245. DSI_PHYSICAL_LANE_1,
  3246. DSI_PHYSICAL_LANE_2);
  3247. } else if (!strcmp(data, "lane_map_0321")) {
  3248. display->lane_map.lane_map_v1 = DSI_LANE_MAP_0321;
  3249. __set_lane_map_v2(display->lane_map.lane_map_v2,
  3250. DSI_PHYSICAL_LANE_0,
  3251. DSI_PHYSICAL_LANE_3,
  3252. DSI_PHYSICAL_LANE_2,
  3253. DSI_PHYSICAL_LANE_1);
  3254. } else if (!strcmp(data, "lane_map_1032")) {
  3255. display->lane_map.lane_map_v1 = DSI_LANE_MAP_1032;
  3256. __set_lane_map_v2(display->lane_map.lane_map_v2,
  3257. DSI_PHYSICAL_LANE_1,
  3258. DSI_PHYSICAL_LANE_0,
  3259. DSI_PHYSICAL_LANE_3,
  3260. DSI_PHYSICAL_LANE_2);
  3261. } else if (!strcmp(data, "lane_map_2103")) {
  3262. display->lane_map.lane_map_v1 = DSI_LANE_MAP_2103;
  3263. __set_lane_map_v2(display->lane_map.lane_map_v2,
  3264. DSI_PHYSICAL_LANE_2,
  3265. DSI_PHYSICAL_LANE_1,
  3266. DSI_PHYSICAL_LANE_0,
  3267. DSI_PHYSICAL_LANE_3);
  3268. } else if (!strcmp(data, "lane_map_3210")) {
  3269. display->lane_map.lane_map_v1 = DSI_LANE_MAP_3210;
  3270. __set_lane_map_v2(display->lane_map.lane_map_v2,
  3271. DSI_PHYSICAL_LANE_3,
  3272. DSI_PHYSICAL_LANE_2,
  3273. DSI_PHYSICAL_LANE_1,
  3274. DSI_PHYSICAL_LANE_0);
  3275. } else {
  3276. DSI_WARN("%s: invalid lane map %s specified. defaulting to lane_map0123\n",
  3277. __func__, data);
  3278. goto set_default;
  3279. }
  3280. return 0;
  3281. set_default:
  3282. /* default lane mapping */
  3283. __set_lane_map_v2(display->lane_map.lane_map_v2, DSI_PHYSICAL_LANE_0,
  3284. DSI_PHYSICAL_LANE_1, DSI_PHYSICAL_LANE_2, DSI_PHYSICAL_LANE_3);
  3285. display->lane_map.lane_map_v1 = DSI_LANE_MAP_0123;
  3286. return 0;
  3287. }
  3288. static int dsi_display_get_phandle_index(
  3289. struct dsi_display *display,
  3290. const char *propname, int count, int index)
  3291. {
  3292. struct device_node *disp_node = display->panel_node;
  3293. u32 *val = NULL;
  3294. int rc = 0;
  3295. val = kcalloc(count, sizeof(*val), GFP_KERNEL);
  3296. if (ZERO_OR_NULL_PTR(val)) {
  3297. rc = -ENOMEM;
  3298. goto end;
  3299. }
  3300. if (index >= count)
  3301. goto end;
  3302. if (display->fw)
  3303. rc = dsi_parser_read_u32_array(display->parser_node,
  3304. propname, val, count);
  3305. else
  3306. rc = of_property_read_u32_array(disp_node, propname,
  3307. val, count);
  3308. if (rc)
  3309. goto end;
  3310. rc = val[index];
  3311. DSI_DEBUG("%s index=%d\n", propname, rc);
  3312. end:
  3313. kfree(val);
  3314. return rc;
  3315. }
  3316. static int dsi_display_get_phandle_count(struct dsi_display *display,
  3317. const char *propname)
  3318. {
  3319. if (display->fw)
  3320. return dsi_parser_count_u32_elems(display->parser_node,
  3321. propname);
  3322. else
  3323. return of_property_count_u32_elems(display->panel_node,
  3324. propname);
  3325. }
  3326. static int dsi_display_parse_dt(struct dsi_display *display)
  3327. {
  3328. int i, rc = 0;
  3329. u32 phy_count = 0;
  3330. struct device_node *of_node = display->pdev->dev.of_node;
  3331. char *dsi_ctrl_name, *dsi_phy_name;
  3332. if (!strcmp(display->display_type, "primary")) {
  3333. dsi_ctrl_name = "qcom,dsi-ctrl-num";
  3334. dsi_phy_name = "qcom,dsi-phy-num";
  3335. } else {
  3336. dsi_ctrl_name = "qcom,dsi-sec-ctrl-num";
  3337. dsi_phy_name = "qcom,dsi-sec-phy-num";
  3338. }
  3339. display->ctrl_count = dsi_display_get_phandle_count(display,
  3340. dsi_ctrl_name);
  3341. phy_count = dsi_display_get_phandle_count(display, dsi_phy_name);
  3342. DSI_DEBUG("ctrl count=%d, phy count=%d\n",
  3343. display->ctrl_count, phy_count);
  3344. if (!phy_count || !display->ctrl_count) {
  3345. DSI_ERR("no ctrl/phys found\n");
  3346. rc = -ENODEV;
  3347. goto error;
  3348. }
  3349. if (phy_count != display->ctrl_count) {
  3350. DSI_ERR("different ctrl and phy counts\n");
  3351. rc = -ENODEV;
  3352. goto error;
  3353. }
  3354. display_for_each_ctrl(i, display) {
  3355. struct dsi_display_ctrl *ctrl = &display->ctrl[i];
  3356. int index;
  3357. index = dsi_display_get_phandle_index(display, dsi_ctrl_name,
  3358. display->ctrl_count, i);
  3359. ctrl->ctrl_of_node = of_parse_phandle(of_node,
  3360. "qcom,dsi-ctrl", index);
  3361. of_node_put(ctrl->ctrl_of_node);
  3362. index = dsi_display_get_phandle_index(display, dsi_phy_name,
  3363. display->ctrl_count, i);
  3364. ctrl->phy_of_node = of_parse_phandle(of_node,
  3365. "qcom,dsi-phy", index);
  3366. of_node_put(ctrl->phy_of_node);
  3367. }
  3368. /* Parse TE data */
  3369. dsi_display_parse_te_data(display);
  3370. /* Parse all external bridges from port 0 */
  3371. display_for_each_ctrl(i, display) {
  3372. display->ext_bridge[i].node_of =
  3373. of_graph_get_remote_node(of_node, 0, i);
  3374. if (display->ext_bridge[i].node_of)
  3375. display->ext_bridge_cnt++;
  3376. else
  3377. break;
  3378. }
  3379. DSI_DEBUG("success\n");
  3380. error:
  3381. return rc;
  3382. }
  3383. static int dsi_display_validate_resources(struct dsi_display *display)
  3384. {
  3385. int rc = 0;
  3386. int i;
  3387. struct dsi_display_ctrl *ctrl;
  3388. display_for_each_ctrl(i, display) {
  3389. ctrl = &display->ctrl[i];
  3390. ctrl->ctrl = dsi_ctrl_get(ctrl->ctrl_of_node);
  3391. if (IS_ERR_OR_NULL(ctrl->ctrl)) {
  3392. rc = PTR_ERR(ctrl->ctrl);
  3393. DSI_ERR("failed to get dsi controller, rc=%d\n", rc);
  3394. ctrl->ctrl = NULL;
  3395. goto error;
  3396. }
  3397. ctrl->phy = dsi_phy_get(ctrl->phy_of_node);
  3398. if (IS_ERR_OR_NULL(ctrl->phy)) {
  3399. rc = PTR_ERR(ctrl->phy);
  3400. DSI_ERR("failed to get phy controller, rc=%d\n", rc);
  3401. dsi_ctrl_put(ctrl->ctrl);
  3402. ctrl->phy = NULL;
  3403. goto error;
  3404. }
  3405. }
  3406. return rc;
  3407. error:
  3408. for (i = i - 1; i >= 0; i--) {
  3409. ctrl = &display->ctrl[i];
  3410. dsi_ctrl_put(ctrl->ctrl);
  3411. dsi_phy_put(ctrl->phy);
  3412. }
  3413. return -EPROBE_DEFER;
  3414. }
  3415. static int dsi_display_res_init(struct dsi_display *display)
  3416. {
  3417. int rc = 0;
  3418. int i;
  3419. display->panel = dsi_panel_get(&display->pdev->dev,
  3420. display->panel_node,
  3421. display->parser_node,
  3422. display->display_type,
  3423. display->cmdline_topology,
  3424. display->trusted_vm_env);
  3425. if (IS_ERR_OR_NULL(display->panel)) {
  3426. rc = PTR_ERR(display->panel);
  3427. DSI_ERR("failed to get panel, rc=%d\n", rc);
  3428. display->panel = NULL;
  3429. goto error;
  3430. }
  3431. display_for_each_ctrl(i, display) {
  3432. struct msm_dsi_phy *phy = display->ctrl[i].phy;
  3433. phy->cfg.force_clk_lane_hs =
  3434. display->panel->host_config.force_hs_clk_lane;
  3435. phy->cfg.phy_type =
  3436. display->panel->host_config.phy_type;
  3437. }
  3438. rc = dsi_display_parse_lane_map(display);
  3439. if (rc) {
  3440. DSI_ERR("Lane map not found, rc=%d\n", rc);
  3441. goto error;
  3442. }
  3443. rc = dsi_display_clocks_init(display);
  3444. if (rc) {
  3445. DSI_ERR("Failed to parse clock data, rc=%d\n", rc);
  3446. goto error;
  3447. }
  3448. /**
  3449. * In trusted vm, the connectors will not be enabled
  3450. * until the HW resources are assigned and accepted.
  3451. */
  3452. if (display->trusted_vm_env)
  3453. display->is_active = false;
  3454. else
  3455. display->is_active = true;
  3456. error:
  3457. return rc;
  3458. }
  3459. static int dsi_display_res_deinit(struct dsi_display *display)
  3460. {
  3461. int rc = 0;
  3462. int i;
  3463. struct dsi_display_ctrl *ctrl;
  3464. display_for_each_ctrl(i, display) {
  3465. ctrl = &display->ctrl[i];
  3466. dsi_phy_put(ctrl->phy);
  3467. dsi_ctrl_put(ctrl->ctrl);
  3468. }
  3469. if (display->panel)
  3470. dsi_panel_put(display->panel);
  3471. return rc;
  3472. }
  3473. static int dsi_display_validate_mode_set(struct dsi_display *display,
  3474. struct dsi_display_mode *mode,
  3475. u32 flags)
  3476. {
  3477. int rc = 0;
  3478. int i;
  3479. struct dsi_display_ctrl *ctrl;
  3480. /*
  3481. * To set a mode:
  3482. * 1. Controllers should be turned off.
  3483. * 2. Link clocks should be off.
  3484. * 3. Phy should be disabled.
  3485. */
  3486. display_for_each_ctrl(i, display) {
  3487. ctrl = &display->ctrl[i];
  3488. if ((ctrl->power_state > DSI_CTRL_POWER_VREG_ON) ||
  3489. (ctrl->phy_enabled)) {
  3490. rc = -EINVAL;
  3491. goto error;
  3492. }
  3493. }
  3494. error:
  3495. return rc;
  3496. }
  3497. static bool dsi_display_is_seamless_dfps_possible(
  3498. const struct dsi_display *display,
  3499. const struct dsi_display_mode *tgt,
  3500. const enum dsi_dfps_type dfps_type)
  3501. {
  3502. struct dsi_display_mode *cur;
  3503. if (!display || !tgt || !display->panel) {
  3504. DSI_ERR("Invalid params\n");
  3505. return false;
  3506. }
  3507. cur = display->panel->cur_mode;
  3508. if (cur->timing.h_active != tgt->timing.h_active) {
  3509. DSI_DEBUG("timing.h_active differs %d %d\n",
  3510. cur->timing.h_active, tgt->timing.h_active);
  3511. return false;
  3512. }
  3513. if (cur->timing.h_back_porch != tgt->timing.h_back_porch) {
  3514. DSI_DEBUG("timing.h_back_porch differs %d %d\n",
  3515. cur->timing.h_back_porch,
  3516. tgt->timing.h_back_porch);
  3517. return false;
  3518. }
  3519. if (cur->timing.h_sync_width != tgt->timing.h_sync_width) {
  3520. DSI_DEBUG("timing.h_sync_width differs %d %d\n",
  3521. cur->timing.h_sync_width,
  3522. tgt->timing.h_sync_width);
  3523. return false;
  3524. }
  3525. if (cur->timing.h_front_porch != tgt->timing.h_front_porch) {
  3526. DSI_DEBUG("timing.h_front_porch differs %d %d\n",
  3527. cur->timing.h_front_porch,
  3528. tgt->timing.h_front_porch);
  3529. if (dfps_type != DSI_DFPS_IMMEDIATE_HFP)
  3530. return false;
  3531. }
  3532. if (cur->timing.h_skew != tgt->timing.h_skew) {
  3533. DSI_DEBUG("timing.h_skew differs %d %d\n",
  3534. cur->timing.h_skew,
  3535. tgt->timing.h_skew);
  3536. return false;
  3537. }
  3538. /* skip polarity comparison */
  3539. if (cur->timing.v_active != tgt->timing.v_active) {
  3540. DSI_DEBUG("timing.v_active differs %d %d\n",
  3541. cur->timing.v_active,
  3542. tgt->timing.v_active);
  3543. return false;
  3544. }
  3545. if (cur->timing.v_back_porch != tgt->timing.v_back_porch) {
  3546. DSI_DEBUG("timing.v_back_porch differs %d %d\n",
  3547. cur->timing.v_back_porch,
  3548. tgt->timing.v_back_porch);
  3549. return false;
  3550. }
  3551. if (cur->timing.v_sync_width != tgt->timing.v_sync_width) {
  3552. DSI_DEBUG("timing.v_sync_width differs %d %d\n",
  3553. cur->timing.v_sync_width,
  3554. tgt->timing.v_sync_width);
  3555. return false;
  3556. }
  3557. if (cur->timing.v_front_porch != tgt->timing.v_front_porch) {
  3558. DSI_DEBUG("timing.v_front_porch differs %d %d\n",
  3559. cur->timing.v_front_porch,
  3560. tgt->timing.v_front_porch);
  3561. if (dfps_type != DSI_DFPS_IMMEDIATE_VFP)
  3562. return false;
  3563. }
  3564. /* skip polarity comparison */
  3565. if (cur->timing.refresh_rate == tgt->timing.refresh_rate)
  3566. DSI_DEBUG("timing.refresh_rate identical %d %d\n",
  3567. cur->timing.refresh_rate,
  3568. tgt->timing.refresh_rate);
  3569. if (cur->pixel_clk_khz != tgt->pixel_clk_khz)
  3570. DSI_DEBUG("pixel_clk_khz differs %d %d\n",
  3571. cur->pixel_clk_khz, tgt->pixel_clk_khz);
  3572. if (cur->dsi_mode_flags != tgt->dsi_mode_flags)
  3573. DSI_DEBUG("flags differs %d %d\n",
  3574. cur->dsi_mode_flags, tgt->dsi_mode_flags);
  3575. return true;
  3576. }
  3577. void dsi_display_update_byte_intf_div(struct dsi_display *display)
  3578. {
  3579. struct dsi_host_common_cfg *config;
  3580. struct dsi_display_ctrl *m_ctrl;
  3581. int phy_ver;
  3582. m_ctrl = &display->ctrl[display->cmd_master_idx];
  3583. config = &display->panel->host_config;
  3584. phy_ver = dsi_phy_get_version(m_ctrl->phy);
  3585. if (phy_ver <= DSI_PHY_VERSION_2_0)
  3586. config->byte_intf_clk_div = 1;
  3587. else
  3588. config->byte_intf_clk_div = 2;
  3589. }
  3590. static int dsi_display_update_dsi_bitrate(struct dsi_display *display,
  3591. u32 bit_clk_rate)
  3592. {
  3593. int rc = 0;
  3594. int i;
  3595. DSI_DEBUG("%s:bit rate:%d\n", __func__, bit_clk_rate);
  3596. if (!display->panel) {
  3597. DSI_ERR("Invalid params\n");
  3598. return -EINVAL;
  3599. }
  3600. if (bit_clk_rate == 0) {
  3601. DSI_ERR("Invalid bit clock rate\n");
  3602. return -EINVAL;
  3603. }
  3604. display->config.bit_clk_rate_hz = bit_clk_rate;
  3605. display_for_each_ctrl(i, display) {
  3606. struct dsi_display_ctrl *dsi_disp_ctrl = &display->ctrl[i];
  3607. struct dsi_ctrl *ctrl = dsi_disp_ctrl->ctrl;
  3608. u32 num_of_lanes = 0, bpp, byte_intf_clk_div;
  3609. u64 bit_rate, pclk_rate, bit_rate_per_lane, byte_clk_rate,
  3610. byte_intf_clk_rate;
  3611. u32 bits_per_symbol = 16, num_of_symbols = 7; /* For Cphy */
  3612. struct dsi_host_common_cfg *host_cfg;
  3613. mutex_lock(&ctrl->ctrl_lock);
  3614. host_cfg = &display->panel->host_config;
  3615. if (host_cfg->data_lanes & DSI_DATA_LANE_0)
  3616. num_of_lanes++;
  3617. if (host_cfg->data_lanes & DSI_DATA_LANE_1)
  3618. num_of_lanes++;
  3619. if (host_cfg->data_lanes & DSI_DATA_LANE_2)
  3620. num_of_lanes++;
  3621. if (host_cfg->data_lanes & DSI_DATA_LANE_3)
  3622. num_of_lanes++;
  3623. if (num_of_lanes == 0) {
  3624. DSI_ERR("Invalid lane count\n");
  3625. rc = -EINVAL;
  3626. goto error;
  3627. }
  3628. bpp = dsi_pixel_format_to_bpp(host_cfg->dst_format);
  3629. bit_rate = display->config.bit_clk_rate_hz * num_of_lanes;
  3630. bit_rate_per_lane = bit_rate;
  3631. do_div(bit_rate_per_lane, num_of_lanes);
  3632. pclk_rate = bit_rate;
  3633. do_div(pclk_rate, bpp);
  3634. if (host_cfg->phy_type == DSI_PHY_TYPE_DPHY) {
  3635. bit_rate_per_lane = bit_rate;
  3636. do_div(bit_rate_per_lane, num_of_lanes);
  3637. byte_clk_rate = bit_rate_per_lane;
  3638. do_div(byte_clk_rate, 8);
  3639. byte_intf_clk_rate = byte_clk_rate;
  3640. byte_intf_clk_div = host_cfg->byte_intf_clk_div;
  3641. do_div(byte_intf_clk_rate, byte_intf_clk_div);
  3642. } else {
  3643. bit_rate_per_lane = bit_clk_rate;
  3644. pclk_rate *= bits_per_symbol;
  3645. do_div(pclk_rate, num_of_symbols);
  3646. byte_clk_rate = bit_clk_rate;
  3647. do_div(byte_clk_rate, num_of_symbols);
  3648. /* For CPHY, byte_intf_clk is same as byte_clk */
  3649. byte_intf_clk_rate = byte_clk_rate;
  3650. }
  3651. DSI_DEBUG("bit_clk_rate = %llu, bit_clk_rate_per_lane = %llu\n",
  3652. bit_rate, bit_rate_per_lane);
  3653. DSI_DEBUG("byte_clk_rate = %llu, byte_intf_clk_rate = %llu\n",
  3654. byte_clk_rate, byte_intf_clk_rate);
  3655. DSI_DEBUG("pclk_rate = %llu\n", pclk_rate);
  3656. SDE_EVT32(i, bit_rate, byte_clk_rate, pclk_rate);
  3657. ctrl->clk_freq.byte_clk_rate = byte_clk_rate;
  3658. ctrl->clk_freq.byte_intf_clk_rate = byte_intf_clk_rate;
  3659. ctrl->clk_freq.pix_clk_rate = pclk_rate;
  3660. rc = dsi_clk_set_link_frequencies(display->dsi_clk_handle,
  3661. ctrl->clk_freq, ctrl->cell_index);
  3662. if (rc) {
  3663. DSI_ERR("Failed to update link frequencies\n");
  3664. goto error;
  3665. }
  3666. ctrl->host_config.bit_clk_rate_hz = bit_clk_rate;
  3667. error:
  3668. mutex_unlock(&ctrl->ctrl_lock);
  3669. /* TODO: recover ctrl->clk_freq in case of failure */
  3670. if (rc)
  3671. return rc;
  3672. }
  3673. return 0;
  3674. }
  3675. static void _dsi_display_calc_pipe_delay(struct dsi_display *display,
  3676. struct dsi_dyn_clk_delay *delay,
  3677. struct dsi_display_mode *mode)
  3678. {
  3679. u32 esc_clk_rate_hz;
  3680. u32 pclk_to_esc_ratio, byte_to_esc_ratio, hr_bit_to_esc_ratio;
  3681. u32 hsync_period = 0;
  3682. struct dsi_display_ctrl *m_ctrl;
  3683. struct dsi_ctrl *dsi_ctrl;
  3684. struct dsi_phy_cfg *cfg;
  3685. int phy_ver;
  3686. m_ctrl = &display->ctrl[display->clk_master_idx];
  3687. dsi_ctrl = m_ctrl->ctrl;
  3688. cfg = &(m_ctrl->phy->cfg);
  3689. esc_clk_rate_hz = dsi_ctrl->clk_freq.esc_clk_rate;
  3690. pclk_to_esc_ratio = (dsi_ctrl->clk_freq.pix_clk_rate /
  3691. esc_clk_rate_hz);
  3692. byte_to_esc_ratio = (dsi_ctrl->clk_freq.byte_clk_rate /
  3693. esc_clk_rate_hz);
  3694. hr_bit_to_esc_ratio = ((dsi_ctrl->clk_freq.byte_clk_rate * 4) /
  3695. esc_clk_rate_hz);
  3696. hsync_period = dsi_h_total_dce(&mode->timing);
  3697. delay->pipe_delay = (hsync_period + 1) / pclk_to_esc_ratio;
  3698. if (!display->panel->video_config.eof_bllp_lp11_en)
  3699. delay->pipe_delay += (17 / pclk_to_esc_ratio) +
  3700. ((21 + (display->config.common_config.t_clk_pre + 1) +
  3701. (display->config.common_config.t_clk_post + 1)) /
  3702. byte_to_esc_ratio) +
  3703. ((((cfg->timing.lane_v3[8] >> 1) + 1) +
  3704. ((cfg->timing.lane_v3[6] >> 1) + 1) +
  3705. ((cfg->timing.lane_v3[3] * 4) +
  3706. (cfg->timing.lane_v3[5] >> 1) + 1) +
  3707. ((cfg->timing.lane_v3[7] >> 1) + 1) +
  3708. ((cfg->timing.lane_v3[1] >> 1) + 1) +
  3709. ((cfg->timing.lane_v3[4] >> 1) + 1)) /
  3710. hr_bit_to_esc_ratio);
  3711. delay->pipe_delay2 = 0;
  3712. if (display->panel->host_config.force_hs_clk_lane)
  3713. delay->pipe_delay2 = (6 / byte_to_esc_ratio) +
  3714. ((((cfg->timing.lane_v3[1] >> 1) + 1) +
  3715. ((cfg->timing.lane_v3[4] >> 1) + 1)) /
  3716. hr_bit_to_esc_ratio);
  3717. /*
  3718. * 100us pll delay recommended for phy ver 2.0 and 3.0
  3719. * 25us pll delay recommended for phy ver 4.0
  3720. */
  3721. phy_ver = dsi_phy_get_version(m_ctrl->phy);
  3722. if (phy_ver <= DSI_PHY_VERSION_3_0)
  3723. delay->pll_delay = 100;
  3724. else
  3725. delay->pll_delay = 25;
  3726. delay->pll_delay = ((delay->pll_delay * esc_clk_rate_hz) / 1000000);
  3727. }
  3728. /*
  3729. * dsi_display_is_type_cphy - check if panel type is cphy
  3730. * @display: Pointer to private display structure
  3731. * Returns: True if panel type is cphy
  3732. */
  3733. static inline bool dsi_display_is_type_cphy(struct dsi_display *display)
  3734. {
  3735. return (display->panel->host_config.phy_type ==
  3736. DSI_PHY_TYPE_CPHY) ? true : false;
  3737. }
  3738. static int _dsi_display_dyn_update_clks(struct dsi_display *display,
  3739. struct link_clk_freq *bkp_freq)
  3740. {
  3741. int rc = 0, i;
  3742. u8 ctrl_version;
  3743. struct dsi_display_ctrl *m_ctrl, *ctrl;
  3744. struct dsi_dyn_clk_caps *dyn_clk_caps;
  3745. struct dsi_clk_link_set *enable_clk;
  3746. m_ctrl = &display->ctrl[display->clk_master_idx];
  3747. dyn_clk_caps = &(display->panel->dyn_clk_caps);
  3748. ctrl_version = m_ctrl->ctrl->version;
  3749. enable_clk = &display->clock_info.pll_clks;
  3750. dsi_clk_prepare_enable(enable_clk);
  3751. dsi_display_phy_configure(display, false);
  3752. display_for_each_ctrl(i, display) {
  3753. ctrl = &display->ctrl[i];
  3754. if (!ctrl->ctrl)
  3755. continue;
  3756. rc = dsi_clk_set_byte_clk_rate(display->dsi_clk_handle,
  3757. ctrl->ctrl->clk_freq.byte_clk_rate,
  3758. ctrl->ctrl->clk_freq.byte_intf_clk_rate, i);
  3759. if (rc) {
  3760. DSI_ERR("failed to set byte rate for index:%d\n", i);
  3761. goto recover_byte_clk;
  3762. }
  3763. rc = dsi_clk_set_pixel_clk_rate(display->dsi_clk_handle,
  3764. ctrl->ctrl->clk_freq.pix_clk_rate, i);
  3765. if (rc) {
  3766. DSI_ERR("failed to set pix rate for index:%d\n", i);
  3767. goto recover_pix_clk;
  3768. }
  3769. }
  3770. display_for_each_ctrl(i, display) {
  3771. ctrl = &display->ctrl[i];
  3772. if (ctrl == m_ctrl)
  3773. continue;
  3774. dsi_phy_dynamic_refresh_trigger(ctrl->phy, false);
  3775. }
  3776. dsi_phy_dynamic_refresh_trigger(m_ctrl->phy, true);
  3777. /*
  3778. * Don't wait for dynamic refresh done for dsi ctrl greater than 2.5
  3779. * and with constant fps, as dynamic refresh will applied with
  3780. * next mdp intf ctrl flush.
  3781. */
  3782. if ((ctrl_version >= DSI_CTRL_VERSION_2_5) &&
  3783. (dyn_clk_caps->maintain_const_fps))
  3784. goto defer_dfps_wait;
  3785. /* wait for dynamic refresh done */
  3786. display_for_each_ctrl(i, display) {
  3787. ctrl = &display->ctrl[i];
  3788. rc = dsi_ctrl_wait4dynamic_refresh_done(ctrl->ctrl);
  3789. if (rc) {
  3790. DSI_ERR("wait4dynamic refresh failed for dsi:%d\n", i);
  3791. goto recover_pix_clk;
  3792. } else {
  3793. DSI_INFO("dynamic refresh done on dsi: %s\n",
  3794. i ? "slave" : "master");
  3795. }
  3796. }
  3797. display_for_each_ctrl(i, display) {
  3798. ctrl = &display->ctrl[i];
  3799. dsi_phy_dynamic_refresh_clear(ctrl->phy);
  3800. }
  3801. defer_dfps_wait:
  3802. if (rc)
  3803. DSI_ERR("could not switch back to src clks %d\n", rc);
  3804. dsi_clk_disable_unprepare(enable_clk);
  3805. return rc;
  3806. recover_pix_clk:
  3807. display_for_each_ctrl(i, display) {
  3808. ctrl = &display->ctrl[i];
  3809. if (!ctrl->ctrl)
  3810. continue;
  3811. dsi_clk_set_pixel_clk_rate(display->dsi_clk_handle,
  3812. bkp_freq->pix_clk_rate, i);
  3813. }
  3814. recover_byte_clk:
  3815. display_for_each_ctrl(i, display) {
  3816. ctrl = &display->ctrl[i];
  3817. if (!ctrl->ctrl)
  3818. continue;
  3819. dsi_clk_set_byte_clk_rate(display->dsi_clk_handle,
  3820. bkp_freq->byte_clk_rate,
  3821. bkp_freq->byte_intf_clk_rate, i);
  3822. }
  3823. return rc;
  3824. }
  3825. static int dsi_display_dynamic_clk_switch_vid(struct dsi_display *display,
  3826. struct dsi_display_mode *mode)
  3827. {
  3828. int rc = 0, mask, i;
  3829. struct dsi_display_ctrl *m_ctrl, *ctrl;
  3830. struct dsi_dyn_clk_delay delay;
  3831. struct link_clk_freq bkp_freq;
  3832. dsi_panel_acquire_panel_lock(display->panel);
  3833. m_ctrl = &display->ctrl[display->clk_master_idx];
  3834. dsi_display_clk_ctrl(display->dsi_clk_handle, DSI_ALL_CLKS, DSI_CLK_ON);
  3835. /* mask PLL unlock, FIFO overflow and underflow errors */
  3836. mask = BIT(DSI_PLL_UNLOCK_ERR) | BIT(DSI_FIFO_UNDERFLOW) |
  3837. BIT(DSI_FIFO_OVERFLOW);
  3838. dsi_display_mask_ctrl_error_interrupts(display, mask, true);
  3839. /* update the phy timings based on new mode */
  3840. display_for_each_ctrl(i, display) {
  3841. ctrl = &display->ctrl[i];
  3842. dsi_phy_update_phy_timings(ctrl->phy, &display->config);
  3843. }
  3844. /* back up existing rates to handle failure case */
  3845. bkp_freq.byte_clk_rate = m_ctrl->ctrl->clk_freq.byte_clk_rate;
  3846. bkp_freq.byte_intf_clk_rate = m_ctrl->ctrl->clk_freq.byte_intf_clk_rate;
  3847. bkp_freq.pix_clk_rate = m_ctrl->ctrl->clk_freq.pix_clk_rate;
  3848. bkp_freq.esc_clk_rate = m_ctrl->ctrl->clk_freq.esc_clk_rate;
  3849. rc = dsi_display_update_dsi_bitrate(display, mode->timing.clk_rate_hz);
  3850. if (rc) {
  3851. DSI_ERR("failed set link frequencies %d\n", rc);
  3852. goto exit;
  3853. }
  3854. /* calculate pipe delays */
  3855. _dsi_display_calc_pipe_delay(display, &delay, mode);
  3856. /* configure dynamic refresh ctrl registers */
  3857. display_for_each_ctrl(i, display) {
  3858. ctrl = &display->ctrl[i];
  3859. if (!ctrl->phy)
  3860. continue;
  3861. if (ctrl == m_ctrl)
  3862. dsi_phy_config_dynamic_refresh(ctrl->phy, &delay, true);
  3863. else
  3864. dsi_phy_config_dynamic_refresh(ctrl->phy, &delay,
  3865. false);
  3866. }
  3867. rc = _dsi_display_dyn_update_clks(display, &bkp_freq);
  3868. exit:
  3869. dsi_display_mask_ctrl_error_interrupts(display, mask, false);
  3870. dsi_display_clk_ctrl(display->dsi_clk_handle, DSI_ALL_CLKS,
  3871. DSI_CLK_OFF);
  3872. /* store newly calculated phy timings in mode private info */
  3873. dsi_phy_dyn_refresh_cache_phy_timings(m_ctrl->phy,
  3874. mode->priv_info->phy_timing_val,
  3875. mode->priv_info->phy_timing_len);
  3876. dsi_panel_release_panel_lock(display->panel);
  3877. return rc;
  3878. }
  3879. static int dsi_display_dynamic_clk_configure_cmd(struct dsi_display *display,
  3880. int clk_rate)
  3881. {
  3882. int rc = 0;
  3883. if (clk_rate <= 0) {
  3884. DSI_ERR("%s: bitrate should be greater than 0\n", __func__);
  3885. return -EINVAL;
  3886. }
  3887. if (clk_rate == display->cached_clk_rate) {
  3888. DSI_INFO("%s: ignore duplicated DSI clk setting\n", __func__);
  3889. return rc;
  3890. }
  3891. display->cached_clk_rate = clk_rate;
  3892. rc = dsi_display_update_dsi_bitrate(display, clk_rate);
  3893. if (!rc) {
  3894. DSI_DEBUG("%s: bit clk is ready to be configured to '%d'\n",
  3895. __func__, clk_rate);
  3896. atomic_set(&display->clkrate_change_pending, 1);
  3897. } else {
  3898. DSI_ERR("%s: Failed to prepare to configure '%d'. rc = %d\n",
  3899. __func__, clk_rate, rc);
  3900. /* Caching clock failed, so don't go on doing so. */
  3901. atomic_set(&display->clkrate_change_pending, 0);
  3902. display->cached_clk_rate = 0;
  3903. }
  3904. return rc;
  3905. }
  3906. static int dsi_display_dfps_update(struct dsi_display *display,
  3907. struct dsi_display_mode *dsi_mode)
  3908. {
  3909. struct dsi_mode_info *timing;
  3910. struct dsi_display_ctrl *m_ctrl, *ctrl;
  3911. struct dsi_display_mode *panel_mode;
  3912. struct dsi_dfps_capabilities dfps_caps;
  3913. int rc = 0;
  3914. int i = 0;
  3915. struct dsi_dyn_clk_caps *dyn_clk_caps;
  3916. if (!display || !dsi_mode || !display->panel) {
  3917. DSI_ERR("Invalid params\n");
  3918. return -EINVAL;
  3919. }
  3920. timing = &dsi_mode->timing;
  3921. dsi_panel_get_dfps_caps(display->panel, &dfps_caps);
  3922. dyn_clk_caps = &(display->panel->dyn_clk_caps);
  3923. if (!dfps_caps.dfps_support && !dyn_clk_caps->maintain_const_fps) {
  3924. DSI_ERR("dfps or constant fps not supported\n");
  3925. return -ENOTSUPP;
  3926. }
  3927. if (dfps_caps.type == DSI_DFPS_IMMEDIATE_CLK) {
  3928. DSI_ERR("dfps clock method not supported\n");
  3929. return -ENOTSUPP;
  3930. }
  3931. /* For split DSI, update the clock master first */
  3932. DSI_DEBUG("configuring seamless dynamic fps\n\n");
  3933. SDE_EVT32(SDE_EVTLOG_FUNC_ENTRY);
  3934. m_ctrl = &display->ctrl[display->clk_master_idx];
  3935. rc = dsi_ctrl_async_timing_update(m_ctrl->ctrl, timing);
  3936. if (rc) {
  3937. DSI_ERR("[%s] failed to dfps update host_%d, rc=%d\n",
  3938. display->name, i, rc);
  3939. goto error;
  3940. }
  3941. /* Update the rest of the controllers */
  3942. display_for_each_ctrl(i, display) {
  3943. ctrl = &display->ctrl[i];
  3944. if (!ctrl->ctrl || (ctrl == m_ctrl))
  3945. continue;
  3946. rc = dsi_ctrl_async_timing_update(ctrl->ctrl, timing);
  3947. if (rc) {
  3948. DSI_ERR("[%s] failed to dfps update host_%d, rc=%d\n",
  3949. display->name, i, rc);
  3950. goto error;
  3951. }
  3952. }
  3953. panel_mode = display->panel->cur_mode;
  3954. memcpy(panel_mode, dsi_mode, sizeof(*panel_mode));
  3955. /*
  3956. * dsi_mode_flags flags are used to communicate with other drm driver
  3957. * components, and are transient. They aren't inherently part of the
  3958. * display panel's mode and shouldn't be saved into the cached currently
  3959. * active mode.
  3960. */
  3961. panel_mode->dsi_mode_flags = 0;
  3962. error:
  3963. SDE_EVT32(SDE_EVTLOG_FUNC_EXIT);
  3964. return rc;
  3965. }
  3966. static int dsi_display_dfps_calc_front_porch(
  3967. u32 old_fps,
  3968. u32 new_fps,
  3969. u32 a_total,
  3970. u32 b_total,
  3971. u32 b_fp,
  3972. u32 *b_fp_out)
  3973. {
  3974. s32 b_fp_new;
  3975. int add_porches, diff;
  3976. if (!b_fp_out) {
  3977. DSI_ERR("Invalid params\n");
  3978. return -EINVAL;
  3979. }
  3980. if (!a_total || !new_fps) {
  3981. DSI_ERR("Invalid pixel total or new fps in mode request\n");
  3982. return -EINVAL;
  3983. }
  3984. /*
  3985. * Keep clock, other porches constant, use new fps, calc front porch
  3986. * new_vtotal = old_vtotal * (old_fps / new_fps )
  3987. * new_vfp - old_vfp = new_vtotal - old_vtotal
  3988. * new_vfp = old_vfp + old_vtotal * ((old_fps - new_fps)/ new_fps)
  3989. */
  3990. diff = abs(old_fps - new_fps);
  3991. add_porches = mult_frac(b_total, diff, new_fps);
  3992. if (old_fps > new_fps)
  3993. b_fp_new = b_fp + add_porches;
  3994. else
  3995. b_fp_new = b_fp - add_porches;
  3996. DSI_DEBUG("fps %u a %u b %u b_fp %u new_fp %d\n",
  3997. new_fps, a_total, b_total, b_fp, b_fp_new);
  3998. if (b_fp_new < 0) {
  3999. DSI_ERR("Invalid new_hfp calcluated%d\n", b_fp_new);
  4000. return -EINVAL;
  4001. }
  4002. /**
  4003. * TODO: To differentiate from clock method when communicating to the
  4004. * other components, perhaps we should set clk here to original value
  4005. */
  4006. *b_fp_out = b_fp_new;
  4007. return 0;
  4008. }
  4009. /**
  4010. * dsi_display_get_dfps_timing() - Get the new dfps values.
  4011. * @display: DSI display handle.
  4012. * @adj_mode: Mode value structure to be changed.
  4013. * It contains old timing values and latest fps value.
  4014. * New timing values are updated based on new fps.
  4015. * @curr_refresh_rate: Current fps rate.
  4016. * If zero , current fps rate is taken from
  4017. * display->panel->cur_mode.
  4018. * Return: error code.
  4019. */
  4020. static int dsi_display_get_dfps_timing(struct dsi_display *display,
  4021. struct dsi_display_mode *adj_mode,
  4022. u32 curr_refresh_rate)
  4023. {
  4024. struct dsi_dfps_capabilities dfps_caps;
  4025. struct dsi_display_mode per_ctrl_mode;
  4026. struct dsi_mode_info *timing;
  4027. struct dsi_ctrl *m_ctrl;
  4028. int rc = 0;
  4029. if (!display || !adj_mode) {
  4030. DSI_ERR("Invalid params\n");
  4031. return -EINVAL;
  4032. }
  4033. m_ctrl = display->ctrl[display->clk_master_idx].ctrl;
  4034. dsi_panel_get_dfps_caps(display->panel, &dfps_caps);
  4035. if (!dfps_caps.dfps_support) {
  4036. DSI_ERR("dfps not supported by panel\n");
  4037. return -EINVAL;
  4038. }
  4039. per_ctrl_mode = *adj_mode;
  4040. adjust_timing_by_ctrl_count(display, &per_ctrl_mode);
  4041. if (!curr_refresh_rate) {
  4042. if (!dsi_display_is_seamless_dfps_possible(display,
  4043. &per_ctrl_mode, dfps_caps.type)) {
  4044. DSI_ERR("seamless dynamic fps not supported for mode\n");
  4045. return -EINVAL;
  4046. }
  4047. if (display->panel->cur_mode) {
  4048. curr_refresh_rate =
  4049. display->panel->cur_mode->timing.refresh_rate;
  4050. } else {
  4051. DSI_ERR("cur_mode is not initialized\n");
  4052. return -EINVAL;
  4053. }
  4054. }
  4055. /* TODO: Remove this direct reference to the dsi_ctrl */
  4056. timing = &per_ctrl_mode.timing;
  4057. switch (dfps_caps.type) {
  4058. case DSI_DFPS_IMMEDIATE_VFP:
  4059. rc = dsi_display_dfps_calc_front_porch(
  4060. curr_refresh_rate,
  4061. timing->refresh_rate,
  4062. dsi_h_total_dce(timing),
  4063. DSI_V_TOTAL(timing),
  4064. timing->v_front_porch,
  4065. &adj_mode->timing.v_front_porch);
  4066. SDE_EVT32(SDE_EVTLOG_FUNC_CASE1, DSI_DFPS_IMMEDIATE_VFP,
  4067. curr_refresh_rate, timing->refresh_rate,
  4068. timing->v_front_porch, adj_mode->timing.v_front_porch);
  4069. break;
  4070. case DSI_DFPS_IMMEDIATE_HFP:
  4071. rc = dsi_display_dfps_calc_front_porch(
  4072. curr_refresh_rate,
  4073. timing->refresh_rate,
  4074. DSI_V_TOTAL(timing),
  4075. dsi_h_total_dce(timing),
  4076. timing->h_front_porch,
  4077. &adj_mode->timing.h_front_porch);
  4078. SDE_EVT32(SDE_EVTLOG_FUNC_CASE2, DSI_DFPS_IMMEDIATE_HFP,
  4079. curr_refresh_rate, timing->refresh_rate,
  4080. timing->h_front_porch, adj_mode->timing.h_front_porch);
  4081. if (!rc)
  4082. adj_mode->timing.h_front_porch *= display->ctrl_count;
  4083. break;
  4084. default:
  4085. DSI_ERR("Unsupported DFPS mode %d\n", dfps_caps.type);
  4086. rc = -ENOTSUPP;
  4087. }
  4088. return rc;
  4089. }
  4090. static bool dsi_display_validate_mode_seamless(struct dsi_display *display,
  4091. struct dsi_display_mode *adj_mode)
  4092. {
  4093. int rc = 0;
  4094. if (!display || !adj_mode) {
  4095. DSI_ERR("Invalid params\n");
  4096. return false;
  4097. }
  4098. /* Currently the only seamless transition is dynamic fps */
  4099. rc = dsi_display_get_dfps_timing(display, adj_mode, 0);
  4100. if (rc) {
  4101. DSI_DEBUG("Dynamic FPS not supported for seamless\n");
  4102. } else {
  4103. DSI_DEBUG("Mode switch is seamless Dynamic FPS\n");
  4104. adj_mode->dsi_mode_flags |= DSI_MODE_FLAG_DFPS |
  4105. DSI_MODE_FLAG_VBLANK_PRE_MODESET;
  4106. }
  4107. return rc;
  4108. }
  4109. static void dsi_display_validate_dms_fps(struct dsi_display_mode *cur_mode,
  4110. struct dsi_display_mode *to_mode)
  4111. {
  4112. u32 cur_fps, to_fps;
  4113. u32 cur_h_active, to_h_active;
  4114. u32 cur_v_active, to_v_active;
  4115. cur_fps = cur_mode->timing.refresh_rate;
  4116. to_fps = to_mode->timing.refresh_rate;
  4117. cur_h_active = cur_mode->timing.h_active;
  4118. cur_v_active = cur_mode->timing.v_active;
  4119. to_h_active = to_mode->timing.h_active;
  4120. to_v_active = to_mode->timing.v_active;
  4121. if ((cur_h_active == to_h_active) && (cur_v_active == to_v_active) &&
  4122. (cur_fps != to_fps)) {
  4123. to_mode->dsi_mode_flags |= DSI_MODE_FLAG_DMS_FPS;
  4124. DSI_DEBUG("DMS Modeset with FPS change\n");
  4125. } else {
  4126. to_mode->dsi_mode_flags &= ~DSI_MODE_FLAG_DMS_FPS;
  4127. }
  4128. }
  4129. static int dsi_display_set_mode_sub(struct dsi_display *display,
  4130. struct dsi_display_mode *mode,
  4131. u32 flags)
  4132. {
  4133. int rc = 0, clk_rate = 0;
  4134. int i;
  4135. struct dsi_display_ctrl *ctrl;
  4136. struct dsi_display_ctrl *mctrl;
  4137. struct dsi_display_mode_priv_info *priv_info;
  4138. bool commit_phy_timing = false;
  4139. struct dsi_dyn_clk_caps *dyn_clk_caps;
  4140. priv_info = mode->priv_info;
  4141. if (!priv_info) {
  4142. DSI_ERR("[%s] failed to get private info of the display mode\n",
  4143. display->name);
  4144. return -EINVAL;
  4145. }
  4146. SDE_EVT32(mode->dsi_mode_flags, display->panel->panel_mode);
  4147. if (mode->dsi_mode_flags & DSI_MODE_FLAG_POMS_TO_VID)
  4148. display->panel->panel_mode = DSI_OP_VIDEO_MODE;
  4149. else if (mode->dsi_mode_flags & DSI_MODE_FLAG_POMS_TO_CMD)
  4150. display->panel->panel_mode = DSI_OP_CMD_MODE;
  4151. rc = dsi_panel_get_host_cfg_for_mode(display->panel,
  4152. mode,
  4153. &display->config);
  4154. if (rc) {
  4155. DSI_ERR("[%s] failed to get host config for mode, rc=%d\n",
  4156. display->name, rc);
  4157. goto error;
  4158. }
  4159. memcpy(&display->config.lane_map, &display->lane_map,
  4160. sizeof(display->lane_map));
  4161. mctrl = &display->ctrl[display->clk_master_idx];
  4162. dyn_clk_caps = &(display->panel->dyn_clk_caps);
  4163. if (mode->dsi_mode_flags &
  4164. (DSI_MODE_FLAG_DFPS | DSI_MODE_FLAG_VRR)) {
  4165. display_for_each_ctrl(i, display) {
  4166. ctrl = &display->ctrl[i];
  4167. if (!ctrl->ctrl || (ctrl != mctrl))
  4168. continue;
  4169. ctrl->ctrl->hw.ops.set_timing_db(&ctrl->ctrl->hw,
  4170. true);
  4171. dsi_phy_dynamic_refresh_clear(ctrl->phy);
  4172. if ((ctrl->ctrl->version >= DSI_CTRL_VERSION_2_5) &&
  4173. (dyn_clk_caps->maintain_const_fps)) {
  4174. dsi_phy_dynamic_refresh_trigger_sel(ctrl->phy,
  4175. true);
  4176. }
  4177. }
  4178. rc = dsi_display_dfps_update(display, mode);
  4179. if (rc) {
  4180. DSI_ERR("[%s]DSI dfps update failed, rc=%d\n",
  4181. display->name, rc);
  4182. goto error;
  4183. }
  4184. display_for_each_ctrl(i, display) {
  4185. ctrl = &display->ctrl[i];
  4186. rc = dsi_ctrl_update_host_config(ctrl->ctrl,
  4187. &display->config, mode, mode->dsi_mode_flags,
  4188. display->dsi_clk_handle);
  4189. if (rc) {
  4190. DSI_ERR("failed to update ctrl config\n");
  4191. goto error;
  4192. }
  4193. }
  4194. if (priv_info->phy_timing_len) {
  4195. display_for_each_ctrl(i, display) {
  4196. ctrl = &display->ctrl[i];
  4197. rc = dsi_phy_set_timing_params(ctrl->phy,
  4198. priv_info->phy_timing_val,
  4199. priv_info->phy_timing_len,
  4200. commit_phy_timing);
  4201. if (rc)
  4202. DSI_ERR("Fail to add timing params\n");
  4203. }
  4204. }
  4205. if (!(mode->dsi_mode_flags & DSI_MODE_FLAG_DYN_CLK))
  4206. return rc;
  4207. }
  4208. if (mode->dsi_mode_flags & DSI_MODE_FLAG_DYN_CLK) {
  4209. if (display->panel->panel_mode == DSI_OP_VIDEO_MODE) {
  4210. rc = dsi_display_dynamic_clk_switch_vid(display, mode);
  4211. if (rc)
  4212. DSI_ERR("dynamic clk change failed %d\n", rc);
  4213. /*
  4214. * skip rest of the opearations since
  4215. * dsi_display_dynamic_clk_switch_vid() already takes
  4216. * care of them.
  4217. */
  4218. return rc;
  4219. } else if (display->panel->panel_mode == DSI_OP_CMD_MODE) {
  4220. clk_rate = mode->timing.clk_rate_hz;
  4221. rc = dsi_display_dynamic_clk_configure_cmd(display,
  4222. clk_rate);
  4223. if (rc) {
  4224. DSI_ERR("Failed to configure dynamic clk\n");
  4225. return rc;
  4226. }
  4227. }
  4228. }
  4229. display_for_each_ctrl(i, display) {
  4230. ctrl = &display->ctrl[i];
  4231. rc = dsi_ctrl_update_host_config(ctrl->ctrl, &display->config,
  4232. mode, mode->dsi_mode_flags,
  4233. display->dsi_clk_handle);
  4234. if (rc) {
  4235. DSI_ERR("[%s] failed to update ctrl config, rc=%d\n",
  4236. display->name, rc);
  4237. goto error;
  4238. }
  4239. }
  4240. if ((mode->dsi_mode_flags & DSI_MODE_FLAG_DMS) &&
  4241. (display->panel->panel_mode == DSI_OP_CMD_MODE)) {
  4242. u64 cur_bitclk = display->panel->cur_mode->timing.clk_rate_hz;
  4243. u64 to_bitclk = mode->timing.clk_rate_hz;
  4244. commit_phy_timing = true;
  4245. /* No need to set clkrate pending flag if clocks are same */
  4246. if ((!cur_bitclk && !to_bitclk) || (cur_bitclk != to_bitclk))
  4247. atomic_set(&display->clkrate_change_pending, 1);
  4248. dsi_display_validate_dms_fps(display->panel->cur_mode, mode);
  4249. }
  4250. if (priv_info->phy_timing_len) {
  4251. display_for_each_ctrl(i, display) {
  4252. ctrl = &display->ctrl[i];
  4253. rc = dsi_phy_set_timing_params(ctrl->phy,
  4254. priv_info->phy_timing_val,
  4255. priv_info->phy_timing_len,
  4256. commit_phy_timing);
  4257. if (rc)
  4258. DSI_ERR("failed to add DSI PHY timing params\n");
  4259. }
  4260. }
  4261. error:
  4262. return rc;
  4263. }
  4264. /**
  4265. * _dsi_display_dev_init - initializes the display device
  4266. * Initialization will acquire references to the resources required for the
  4267. * display hardware to function.
  4268. * @display: Handle to the display
  4269. * Returns: Zero on success
  4270. */
  4271. static int _dsi_display_dev_init(struct dsi_display *display)
  4272. {
  4273. int rc = 0;
  4274. if (!display) {
  4275. DSI_ERR("invalid display\n");
  4276. return -EINVAL;
  4277. }
  4278. if (!display->panel_node && !display->fw)
  4279. return 0;
  4280. mutex_lock(&display->display_lock);
  4281. display->parser = dsi_parser_get(&display->pdev->dev);
  4282. if (display->fw && display->parser)
  4283. display->parser_node = dsi_parser_get_head_node(
  4284. display->parser, display->fw->data,
  4285. display->fw->size);
  4286. rc = dsi_display_res_init(display);
  4287. if (rc) {
  4288. DSI_ERR("[%s] failed to initialize resources, rc=%d\n",
  4289. display->name, rc);
  4290. goto error;
  4291. }
  4292. error:
  4293. mutex_unlock(&display->display_lock);
  4294. return rc;
  4295. }
  4296. /**
  4297. * _dsi_display_dev_deinit - deinitializes the display device
  4298. * All the resources acquired during device init will be released.
  4299. * @display: Handle to the display
  4300. * Returns: Zero on success
  4301. */
  4302. static int _dsi_display_dev_deinit(struct dsi_display *display)
  4303. {
  4304. int rc = 0;
  4305. if (!display) {
  4306. DSI_ERR("invalid display\n");
  4307. return -EINVAL;
  4308. }
  4309. mutex_lock(&display->display_lock);
  4310. rc = dsi_display_res_deinit(display);
  4311. if (rc)
  4312. DSI_ERR("[%s] failed to deinitialize resource, rc=%d\n",
  4313. display->name, rc);
  4314. mutex_unlock(&display->display_lock);
  4315. return rc;
  4316. }
  4317. /**
  4318. * dsi_display_cont_splash_res_disable() - Disable resource votes added in probe
  4319. * @dsi_display: Pointer to dsi display
  4320. * Returns: Zero on success
  4321. */
  4322. int dsi_display_cont_splash_res_disable(void *dsi_display)
  4323. {
  4324. struct dsi_display *display = dsi_display;
  4325. int rc = 0;
  4326. /* Remove the panel vote that was added during dsi display probe */
  4327. rc = dsi_pwr_enable_regulator(&display->panel->power_info, false);
  4328. if (rc)
  4329. DSI_ERR("[%s] failed to disable vregs, rc=%d\n",
  4330. display->panel->name, rc);
  4331. return rc;
  4332. }
  4333. /**
  4334. * dsi_display_cont_splash_config() - Initialize resources for continuous splash
  4335. * @dsi_display: Pointer to dsi display
  4336. * Returns: Zero on success
  4337. */
  4338. int dsi_display_cont_splash_config(void *dsi_display)
  4339. {
  4340. struct dsi_display *display = dsi_display;
  4341. int rc = 0;
  4342. /* Vote for gdsc required to read register address space */
  4343. if (!display) {
  4344. DSI_ERR("invalid input display param\n");
  4345. return -EINVAL;
  4346. }
  4347. rc = pm_runtime_get_sync(display->drm_dev->dev);
  4348. if (rc < 0) {
  4349. DSI_ERR("failed to vote gdsc for continuous splash, rc=%d\n",
  4350. rc);
  4351. return rc;
  4352. }
  4353. mutex_lock(&display->display_lock);
  4354. display->is_cont_splash_enabled = true;
  4355. /* Update splash status for clock manager */
  4356. dsi_display_clk_mngr_update_splash_status(display->clk_mngr,
  4357. display->is_cont_splash_enabled);
  4358. SDE_EVT32(SDE_EVTLOG_FUNC_ENTRY, display->is_cont_splash_enabled);
  4359. /* Set up ctrl isr before enabling core clk */
  4360. dsi_display_ctrl_isr_configure(display, true);
  4361. /* Vote for Core clk and link clk. Votes on ctrl and phy
  4362. * regulator are inplicit from pre clk on callback
  4363. */
  4364. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  4365. DSI_ALL_CLKS, DSI_CLK_ON);
  4366. if (rc) {
  4367. DSI_ERR("[%s] failed to enable DSI link clocks, rc=%d\n",
  4368. display->name, rc);
  4369. goto clk_manager_update;
  4370. }
  4371. mutex_unlock(&display->display_lock);
  4372. /* Set the current brightness level */
  4373. dsi_panel_bl_handoff(display->panel);
  4374. return rc;
  4375. clk_manager_update:
  4376. dsi_display_ctrl_isr_configure(display, false);
  4377. /* Update splash status for clock manager */
  4378. dsi_display_clk_mngr_update_splash_status(display->clk_mngr,
  4379. false);
  4380. pm_runtime_put_sync(display->drm_dev->dev);
  4381. display->is_cont_splash_enabled = false;
  4382. mutex_unlock(&display->display_lock);
  4383. return rc;
  4384. }
  4385. /**
  4386. * dsi_display_splash_res_cleanup() - cleanup for continuous splash
  4387. * @display: Pointer to dsi display
  4388. * Returns: Zero on success
  4389. */
  4390. int dsi_display_splash_res_cleanup(struct dsi_display *display)
  4391. {
  4392. int rc = 0;
  4393. if (!display->is_cont_splash_enabled)
  4394. return 0;
  4395. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  4396. DSI_ALL_CLKS, DSI_CLK_OFF);
  4397. if (rc)
  4398. DSI_ERR("[%s] failed to disable DSI link clocks, rc=%d\n",
  4399. display->name, rc);
  4400. pm_runtime_put_sync(display->drm_dev->dev);
  4401. display->is_cont_splash_enabled = false;
  4402. /* Update splash status for clock manager */
  4403. dsi_display_clk_mngr_update_splash_status(display->clk_mngr,
  4404. display->is_cont_splash_enabled);
  4405. SDE_EVT32(SDE_EVTLOG_FUNC_EXIT, display->is_cont_splash_enabled);
  4406. return rc;
  4407. }
  4408. static int dsi_display_force_update_dsi_clk(struct dsi_display *display)
  4409. {
  4410. int rc = 0;
  4411. rc = dsi_display_link_clk_force_update_ctrl(display->dsi_clk_handle);
  4412. if (!rc) {
  4413. DSI_DEBUG("dsi bit clk has been configured to %d\n",
  4414. display->cached_clk_rate);
  4415. atomic_set(&display->clkrate_change_pending, 0);
  4416. } else {
  4417. DSI_ERR("Failed to configure dsi bit clock '%d'. rc = %d\n",
  4418. display->cached_clk_rate, rc);
  4419. }
  4420. return rc;
  4421. }
  4422. static int dsi_display_validate_split_link(struct dsi_display *display)
  4423. {
  4424. int i, rc = 0;
  4425. struct dsi_display_ctrl *ctrl;
  4426. struct dsi_host_common_cfg *host = &display->panel->host_config;
  4427. if (!host->split_link.split_link_enabled)
  4428. return 0;
  4429. if (display->panel->panel_mode == DSI_OP_CMD_MODE) {
  4430. DSI_ERR("[%s] split link is not supported in command mode\n",
  4431. display->name);
  4432. rc = -ENOTSUPP;
  4433. goto error;
  4434. }
  4435. display_for_each_ctrl(i, display) {
  4436. ctrl = &display->ctrl[i];
  4437. if (!ctrl->ctrl->split_link_supported) {
  4438. DSI_ERR("[%s] split link is not supported by hw\n",
  4439. display->name);
  4440. rc = -ENOTSUPP;
  4441. goto error;
  4442. }
  4443. set_bit(DSI_PHY_SPLIT_LINK, ctrl->phy->hw.feature_map);
  4444. }
  4445. DSI_DEBUG("Split link is enabled\n");
  4446. return 0;
  4447. error:
  4448. host->split_link.split_link_enabled = false;
  4449. return rc;
  4450. }
  4451. static int dsi_display_get_io_resources(struct msm_io_res *io_res, void *data)
  4452. {
  4453. int rc = 0;
  4454. struct dsi_display *display;
  4455. if (!data)
  4456. return -EINVAL;
  4457. rc = dsi_ctrl_get_io_resources(io_res);
  4458. if (rc)
  4459. goto end;
  4460. rc = dsi_phy_get_io_resources(io_res);
  4461. if (rc)
  4462. goto end;
  4463. display = (struct dsi_display *)data;
  4464. rc = dsi_panel_get_io_resources(display->panel, io_res);
  4465. end:
  4466. return rc;
  4467. }
  4468. static int dsi_display_pre_release(void *data)
  4469. {
  4470. if (!data)
  4471. return -EINVAL;
  4472. dsi_display_ctrl_irq_update((struct dsi_display *)data, false);
  4473. return 0;
  4474. }
  4475. static int dsi_display_pre_acquire(void *data)
  4476. {
  4477. if (!data)
  4478. return -EINVAL;
  4479. dsi_display_ctrl_irq_update((struct dsi_display *)data, true);
  4480. return 0;
  4481. }
  4482. /**
  4483. * dsi_display_bind - bind dsi device with controlling device
  4484. * @dev: Pointer to base of platform device
  4485. * @master: Pointer to container of drm device
  4486. * @data: Pointer to private data
  4487. * Returns: Zero on success
  4488. */
  4489. static int dsi_display_bind(struct device *dev,
  4490. struct device *master,
  4491. void *data)
  4492. {
  4493. struct dsi_display_ctrl *display_ctrl;
  4494. struct drm_device *drm;
  4495. struct dsi_display *display;
  4496. struct dsi_clk_info info;
  4497. struct clk_ctrl_cb clk_cb;
  4498. void *handle = NULL;
  4499. struct platform_device *pdev = to_platform_device(dev);
  4500. char *client1 = "dsi_clk_client";
  4501. char *client2 = "mdp_event_client";
  4502. struct msm_vm_ops vm_event_ops = {
  4503. .vm_get_io_resources = dsi_display_get_io_resources,
  4504. .vm_pre_hw_release = dsi_display_pre_release,
  4505. .vm_post_hw_acquire = dsi_display_pre_acquire,
  4506. };
  4507. int i, rc = 0;
  4508. if (!dev || !pdev || !master) {
  4509. DSI_ERR("invalid param(s), dev %pK, pdev %pK, master %pK\n",
  4510. dev, pdev, master);
  4511. return -EINVAL;
  4512. }
  4513. drm = dev_get_drvdata(master);
  4514. display = platform_get_drvdata(pdev);
  4515. if (!drm || !display) {
  4516. DSI_ERR("invalid param(s), drm %pK, display %pK\n",
  4517. drm, display);
  4518. return -EINVAL;
  4519. }
  4520. if (!display->panel_node && !display->fw)
  4521. return 0;
  4522. if (!display->fw)
  4523. display->name = display->panel_node->name;
  4524. /* defer bind if ext bridge driver is not loaded */
  4525. if (display->panel && display->panel->host_config.ext_bridge_mode) {
  4526. for (i = 0; i < display->ext_bridge_cnt; i++) {
  4527. if (!of_drm_find_bridge(
  4528. display->ext_bridge[i].node_of)) {
  4529. DSI_DEBUG("defer for bridge[%d] %s\n", i,
  4530. display->ext_bridge[i].node_of->full_name);
  4531. return -EPROBE_DEFER;
  4532. }
  4533. }
  4534. }
  4535. mutex_lock(&display->display_lock);
  4536. rc = dsi_display_validate_split_link(display);
  4537. if (rc) {
  4538. DSI_ERR("[%s] split link validation failed, rc=%d\n",
  4539. display->name, rc);
  4540. goto error;
  4541. }
  4542. rc = dsi_display_debugfs_init(display);
  4543. if (rc) {
  4544. DSI_ERR("[%s] debugfs init failed, rc=%d\n", display->name, rc);
  4545. goto error;
  4546. }
  4547. atomic_set(&display->clkrate_change_pending, 0);
  4548. display->cached_clk_rate = 0;
  4549. memset(&info, 0x0, sizeof(info));
  4550. display_for_each_ctrl(i, display) {
  4551. display_ctrl = &display->ctrl[i];
  4552. rc = dsi_ctrl_drv_init(display_ctrl->ctrl, display->root);
  4553. if (rc) {
  4554. DSI_ERR("[%s] failed to initialize ctrl[%d], rc=%d\n",
  4555. display->name, i, rc);
  4556. goto error_ctrl_deinit;
  4557. }
  4558. display_ctrl->ctrl->horiz_index = i;
  4559. rc = dsi_phy_drv_init(display_ctrl->phy);
  4560. if (rc) {
  4561. DSI_ERR("[%s] Failed to initialize phy[%d], rc=%d\n",
  4562. display->name, i, rc);
  4563. (void)dsi_ctrl_drv_deinit(display_ctrl->ctrl);
  4564. goto error_ctrl_deinit;
  4565. }
  4566. display_ctrl->ctrl->dma_cmd_workq = display->dma_cmd_workq;
  4567. memcpy(&info.c_clks[i],
  4568. (&display_ctrl->ctrl->clk_info.core_clks),
  4569. sizeof(struct dsi_core_clk_info));
  4570. memcpy(&info.l_hs_clks[i],
  4571. (&display_ctrl->ctrl->clk_info.hs_link_clks),
  4572. sizeof(struct dsi_link_hs_clk_info));
  4573. memcpy(&info.l_lp_clks[i],
  4574. (&display_ctrl->ctrl->clk_info.lp_link_clks),
  4575. sizeof(struct dsi_link_lp_clk_info));
  4576. info.c_clks[i].drm = drm;
  4577. info.ctrl_index[i] = display_ctrl->ctrl->cell_index;
  4578. }
  4579. info.pre_clkoff_cb = dsi_pre_clkoff_cb;
  4580. info.pre_clkon_cb = dsi_pre_clkon_cb;
  4581. info.post_clkoff_cb = dsi_post_clkoff_cb;
  4582. info.post_clkon_cb = dsi_post_clkon_cb;
  4583. info.phy_config_cb = dsi_display_phy_configure;
  4584. info.phy_pll_toggle_cb = dsi_display_phy_pll_toggle;
  4585. info.priv_data = display;
  4586. info.master_ndx = display->clk_master_idx;
  4587. info.dsi_ctrl_count = display->ctrl_count;
  4588. snprintf(info.name, MAX_STRING_LEN,
  4589. "DSI_MNGR-%s", display->name);
  4590. display->clk_mngr = dsi_display_clk_mngr_register(&info);
  4591. if (IS_ERR_OR_NULL(display->clk_mngr)) {
  4592. rc = PTR_ERR(display->clk_mngr);
  4593. display->clk_mngr = NULL;
  4594. DSI_ERR("dsi clock registration failed, rc = %d\n", rc);
  4595. goto error_ctrl_deinit;
  4596. }
  4597. handle = dsi_register_clk_handle(display->clk_mngr, client1);
  4598. if (IS_ERR_OR_NULL(handle)) {
  4599. rc = PTR_ERR(handle);
  4600. DSI_ERR("failed to register %s client, rc = %d\n",
  4601. client1, rc);
  4602. goto error_clk_deinit;
  4603. } else {
  4604. display->dsi_clk_handle = handle;
  4605. }
  4606. handle = dsi_register_clk_handle(display->clk_mngr, client2);
  4607. if (IS_ERR_OR_NULL(handle)) {
  4608. rc = PTR_ERR(handle);
  4609. DSI_ERR("failed to register %s client, rc = %d\n",
  4610. client2, rc);
  4611. goto error_clk_client_deinit;
  4612. } else {
  4613. display->mdp_clk_handle = handle;
  4614. }
  4615. clk_cb.priv = display;
  4616. clk_cb.dsi_clk_cb = dsi_display_clk_ctrl_cb;
  4617. display_for_each_ctrl(i, display) {
  4618. display_ctrl = &display->ctrl[i];
  4619. rc = dsi_ctrl_clk_cb_register(display_ctrl->ctrl, &clk_cb);
  4620. if (rc) {
  4621. DSI_ERR("[%s] failed to register ctrl clk_cb[%d], rc=%d\n",
  4622. display->name, i, rc);
  4623. goto error_ctrl_deinit;
  4624. }
  4625. rc = dsi_phy_clk_cb_register(display_ctrl->phy, &clk_cb);
  4626. if (rc) {
  4627. DSI_ERR("[%s] failed to register phy clk_cb[%d], rc=%d\n",
  4628. display->name, i, rc);
  4629. goto error_ctrl_deinit;
  4630. }
  4631. }
  4632. dsi_display_update_byte_intf_div(display);
  4633. rc = dsi_display_mipi_host_init(display);
  4634. if (rc) {
  4635. DSI_ERR("[%s] failed to initialize mipi host, rc=%d\n",
  4636. display->name, rc);
  4637. goto error_ctrl_deinit;
  4638. }
  4639. rc = dsi_panel_drv_init(display->panel, &display->host);
  4640. if (rc) {
  4641. if (rc != -EPROBE_DEFER)
  4642. DSI_ERR("[%s] failed to initialize panel driver, rc=%d\n",
  4643. display->name, rc);
  4644. goto error_host_deinit;
  4645. }
  4646. DSI_INFO("Successfully bind display panel '%s'\n", display->name);
  4647. display->drm_dev = drm;
  4648. display_for_each_ctrl(i, display) {
  4649. display_ctrl = &display->ctrl[i];
  4650. if (!display_ctrl->phy || !display_ctrl->ctrl)
  4651. continue;
  4652. display_ctrl->ctrl->drm_dev = drm;
  4653. rc = dsi_phy_set_clk_freq(display_ctrl->phy,
  4654. &display_ctrl->ctrl->clk_freq);
  4655. if (rc) {
  4656. DSI_ERR("[%s] failed to set phy clk freq, rc=%d\n",
  4657. display->name, rc);
  4658. goto error;
  4659. }
  4660. }
  4661. /* register te irq handler */
  4662. dsi_display_register_te_irq(display);
  4663. msm_register_vm_event(master, dev, &vm_event_ops, (void *)display);
  4664. goto error;
  4665. error_host_deinit:
  4666. (void)dsi_display_mipi_host_deinit(display);
  4667. error_clk_client_deinit:
  4668. (void)dsi_deregister_clk_handle(display->dsi_clk_handle);
  4669. error_clk_deinit:
  4670. (void)dsi_display_clk_mngr_deregister(display->clk_mngr);
  4671. error_ctrl_deinit:
  4672. for (i = i - 1; i >= 0; i--) {
  4673. display_ctrl = &display->ctrl[i];
  4674. (void)dsi_phy_drv_deinit(display_ctrl->phy);
  4675. (void)dsi_ctrl_drv_deinit(display_ctrl->ctrl);
  4676. }
  4677. (void)dsi_display_debugfs_deinit(display);
  4678. error:
  4679. mutex_unlock(&display->display_lock);
  4680. return rc;
  4681. }
  4682. /**
  4683. * dsi_display_unbind - unbind dsi from controlling device
  4684. * @dev: Pointer to base of platform device
  4685. * @master: Pointer to container of drm device
  4686. * @data: Pointer to private data
  4687. */
  4688. static void dsi_display_unbind(struct device *dev,
  4689. struct device *master, void *data)
  4690. {
  4691. struct dsi_display_ctrl *display_ctrl;
  4692. struct dsi_display *display;
  4693. struct platform_device *pdev = to_platform_device(dev);
  4694. int i, rc = 0;
  4695. if (!dev || !pdev || !master) {
  4696. DSI_ERR("invalid param(s)\n");
  4697. return;
  4698. }
  4699. display = platform_get_drvdata(pdev);
  4700. if (!display || !display->panel_node) {
  4701. DSI_ERR("invalid display\n");
  4702. return;
  4703. }
  4704. mutex_lock(&display->display_lock);
  4705. rc = dsi_display_mipi_host_deinit(display);
  4706. if (rc)
  4707. DSI_ERR("[%s] failed to deinit mipi hosts, rc=%d\n",
  4708. display->name,
  4709. rc);
  4710. display_for_each_ctrl(i, display) {
  4711. display_ctrl = &display->ctrl[i];
  4712. rc = dsi_phy_drv_deinit(display_ctrl->phy);
  4713. if (rc)
  4714. DSI_ERR("[%s] failed to deinit phy%d driver, rc=%d\n",
  4715. display->name, i, rc);
  4716. display->ctrl->ctrl->dma_cmd_workq = NULL;
  4717. rc = dsi_ctrl_drv_deinit(display_ctrl->ctrl);
  4718. if (rc)
  4719. DSI_ERR("[%s] failed to deinit ctrl%d driver, rc=%d\n",
  4720. display->name, i, rc);
  4721. }
  4722. atomic_set(&display->clkrate_change_pending, 0);
  4723. (void)dsi_display_debugfs_deinit(display);
  4724. mutex_unlock(&display->display_lock);
  4725. }
  4726. static const struct component_ops dsi_display_comp_ops = {
  4727. .bind = dsi_display_bind,
  4728. .unbind = dsi_display_unbind,
  4729. };
  4730. static struct platform_driver dsi_display_driver = {
  4731. .probe = dsi_display_dev_probe,
  4732. .remove = dsi_display_dev_remove,
  4733. .driver = {
  4734. .name = "msm-dsi-display",
  4735. .of_match_table = dsi_display_dt_match,
  4736. .suppress_bind_attrs = true,
  4737. },
  4738. };
  4739. static int dsi_display_init(struct dsi_display *display)
  4740. {
  4741. int rc = 0;
  4742. struct platform_device *pdev = display->pdev;
  4743. rc = _dsi_display_dev_init(display);
  4744. if (rc) {
  4745. DSI_ERR("device init failed, rc=%d\n", rc);
  4746. goto end;
  4747. }
  4748. /*
  4749. * Vote on panel regulator is added to make sure panel regulators
  4750. * are ON for cont-splash enabled usecase.
  4751. * This panel regulator vote will be removed only in:
  4752. * 1) device suspend when cont-splash is enabled.
  4753. * 2) cont_splash_res_disable() when cont-splash is disabled.
  4754. * For GKI, adding this vote will make sure that sync_state
  4755. * kernel driver doesn't disable the panel regulators after
  4756. * dsi probe is complete.
  4757. */
  4758. if (display->panel) {
  4759. rc = dsi_pwr_enable_regulator(&display->panel->power_info,
  4760. true);
  4761. if (rc) {
  4762. DSI_ERR("[%s] failed to enable vregs, rc=%d\n",
  4763. display->panel->name, rc);
  4764. return rc;
  4765. }
  4766. }
  4767. rc = component_add(&pdev->dev, &dsi_display_comp_ops);
  4768. if (rc)
  4769. DSI_ERR("component add failed, rc=%d\n", rc);
  4770. DSI_DEBUG("component add success: %s\n", display->name);
  4771. end:
  4772. return rc;
  4773. }
  4774. static void dsi_display_firmware_display(const struct firmware *fw,
  4775. void *context)
  4776. {
  4777. struct dsi_display *display = context;
  4778. if (fw) {
  4779. DSI_INFO("reading data from firmware, size=%zd\n",
  4780. fw->size);
  4781. display->fw = fw;
  4782. if (!strcmp(display->display_type, "primary"))
  4783. display->name = "dsi_firmware_display";
  4784. else if (!strcmp(display->display_type, "secondary"))
  4785. display->name = "dsi_firmware_display_secondary";
  4786. } else {
  4787. DSI_INFO("no firmware available, fallback to device node\n");
  4788. }
  4789. if (dsi_display_init(display))
  4790. return;
  4791. DSI_DEBUG("success\n");
  4792. }
  4793. int dsi_display_dev_probe(struct platform_device *pdev)
  4794. {
  4795. struct dsi_display *display = NULL;
  4796. struct device_node *node = NULL, *panel_node = NULL, *mdp_node = NULL;
  4797. int rc = 0, index = DSI_PRIMARY;
  4798. bool firm_req = false;
  4799. struct dsi_display_boot_param *boot_disp;
  4800. if (!pdev || !pdev->dev.of_node) {
  4801. DSI_ERR("pdev not found\n");
  4802. rc = -ENODEV;
  4803. goto end;
  4804. }
  4805. display = devm_kzalloc(&pdev->dev, sizeof(*display), GFP_KERNEL);
  4806. if (!display) {
  4807. rc = -ENOMEM;
  4808. goto end;
  4809. }
  4810. mutex_init(&display->display_lock);
  4811. display->dma_cmd_workq = create_singlethread_workqueue(
  4812. "dsi_dma_cmd_workq");
  4813. if (!display->dma_cmd_workq) {
  4814. DSI_ERR("failed to create work queue\n");
  4815. rc = -EINVAL;
  4816. goto end;
  4817. }
  4818. mdp_node = of_parse_phandle(pdev->dev.of_node, "qcom,mdp", 0);
  4819. if (!mdp_node) {
  4820. DSI_ERR("mdp_node not found\n");
  4821. rc = -ENODEV;
  4822. goto end;
  4823. }
  4824. display->trusted_vm_env = of_property_read_bool(mdp_node,
  4825. "qcom,sde-trusted-vm-env");
  4826. if (display->trusted_vm_env)
  4827. DSI_INFO("Display enabled with trusted vm path\n");
  4828. /* initialize panel id to UINT64_MAX */
  4829. display->panel_id = ~0x0;
  4830. display->display_type = of_get_property(pdev->dev.of_node,
  4831. "label", NULL);
  4832. if (!display->display_type)
  4833. display->display_type = "primary";
  4834. if (!strcmp(display->display_type, "secondary"))
  4835. index = DSI_SECONDARY;
  4836. boot_disp = &boot_displays[index];
  4837. node = pdev->dev.of_node;
  4838. if (boot_disp->boot_disp_en) {
  4839. /* The panel name should be same as UEFI name index */
  4840. panel_node = of_find_node_by_name(mdp_node, boot_disp->name);
  4841. if (!panel_node)
  4842. DSI_WARN("panel_node %s not found\n", boot_disp->name);
  4843. } else {
  4844. panel_node = of_parse_phandle(node,
  4845. "qcom,dsi-default-panel", 0);
  4846. if (!panel_node)
  4847. DSI_WARN("default panel not found\n");
  4848. }
  4849. boot_disp->node = pdev->dev.of_node;
  4850. boot_disp->disp = display;
  4851. display->panel_node = panel_node;
  4852. display->pdev = pdev;
  4853. display->boot_disp = boot_disp;
  4854. dsi_display_parse_cmdline_topology(display, index);
  4855. platform_set_drvdata(pdev, display);
  4856. rc = dsi_display_parse_dt(display);
  4857. if (rc) {
  4858. DSI_ERR("[%s] failed to parse dt, rc=%d\n", display->name, rc);
  4859. goto end;
  4860. }
  4861. rc = dsi_display_validate_resources(display);
  4862. if (rc) {
  4863. DSI_ERR("[%s] needed resources not probed yet, rc=%d\n",
  4864. display->name, rc);
  4865. goto end;
  4866. }
  4867. /* initialize display in firmware callback */
  4868. if (!boot_disp->boot_disp_en &&
  4869. IS_ENABLED(CONFIG_DSI_PARSER) &&
  4870. !display->trusted_vm_env) {
  4871. if (!strcmp(display->display_type, "primary"))
  4872. firm_req = !request_firmware_nowait(
  4873. THIS_MODULE, 1, "dsi_prop",
  4874. &pdev->dev, GFP_KERNEL, display,
  4875. dsi_display_firmware_display);
  4876. else if (!strcmp(display->display_type, "secondary"))
  4877. firm_req = !request_firmware_nowait(
  4878. THIS_MODULE, 1, "dsi_prop_sec",
  4879. &pdev->dev, GFP_KERNEL, display,
  4880. dsi_display_firmware_display);
  4881. }
  4882. if (!firm_req) {
  4883. rc = dsi_display_init(display);
  4884. if (rc)
  4885. goto end;
  4886. }
  4887. return 0;
  4888. end:
  4889. if (display) {
  4890. mutex_destroy(&display->display_lock);
  4891. devm_kfree(&pdev->dev, display);
  4892. }
  4893. return rc;
  4894. }
  4895. int dsi_display_dev_remove(struct platform_device *pdev)
  4896. {
  4897. int rc = 0, i = 0;
  4898. struct dsi_display *display;
  4899. struct dsi_display_ctrl *ctrl;
  4900. if (!pdev) {
  4901. DSI_ERR("Invalid device\n");
  4902. return -EINVAL;
  4903. }
  4904. display = platform_get_drvdata(pdev);
  4905. /* decrement ref count */
  4906. of_node_put(display->panel_node);
  4907. if (display->dma_cmd_workq) {
  4908. flush_workqueue(display->dma_cmd_workq);
  4909. destroy_workqueue(display->dma_cmd_workq);
  4910. display->dma_cmd_workq = NULL;
  4911. display_for_each_ctrl(i, display) {
  4912. ctrl = &display->ctrl[i];
  4913. if (!ctrl->ctrl)
  4914. continue;
  4915. ctrl->ctrl->dma_cmd_workq = NULL;
  4916. }
  4917. }
  4918. (void)_dsi_display_dev_deinit(display);
  4919. platform_set_drvdata(pdev, NULL);
  4920. devm_kfree(&pdev->dev, display);
  4921. return rc;
  4922. }
  4923. int dsi_display_get_num_of_displays(void)
  4924. {
  4925. int i, count = 0;
  4926. for (i = 0; i < MAX_DSI_ACTIVE_DISPLAY; i++) {
  4927. struct dsi_display *display = boot_displays[i].disp;
  4928. if ((display && display->panel_node) ||
  4929. (display && display->fw))
  4930. count++;
  4931. }
  4932. return count;
  4933. }
  4934. int dsi_display_get_active_displays(void **display_array, u32 max_display_count)
  4935. {
  4936. int index = 0, count = 0;
  4937. if (!display_array || !max_display_count) {
  4938. DSI_ERR("invalid params\n");
  4939. return 0;
  4940. }
  4941. for (index = 0; index < MAX_DSI_ACTIVE_DISPLAY; index++) {
  4942. struct dsi_display *display = boot_displays[index].disp;
  4943. if ((display && display->panel_node) ||
  4944. (display && display->fw))
  4945. display_array[count++] = display;
  4946. }
  4947. return count;
  4948. }
  4949. void dsi_display_set_active_state(struct dsi_display *display, bool is_active)
  4950. {
  4951. if (!display)
  4952. return;
  4953. mutex_lock(&display->display_lock);
  4954. display->is_active = is_active;
  4955. mutex_unlock(&display->display_lock);
  4956. }
  4957. int dsi_display_drm_bridge_init(struct dsi_display *display,
  4958. struct drm_encoder *enc)
  4959. {
  4960. int rc = 0;
  4961. struct dsi_bridge *bridge;
  4962. struct msm_drm_private *priv = NULL;
  4963. if (!display || !display->drm_dev || !enc) {
  4964. DSI_ERR("invalid param(s)\n");
  4965. return -EINVAL;
  4966. }
  4967. mutex_lock(&display->display_lock);
  4968. priv = display->drm_dev->dev_private;
  4969. if (!priv) {
  4970. DSI_ERR("Private data is not present\n");
  4971. rc = -EINVAL;
  4972. goto error;
  4973. }
  4974. if (display->bridge) {
  4975. DSI_ERR("display is already initialize\n");
  4976. goto error;
  4977. }
  4978. bridge = dsi_drm_bridge_init(display, display->drm_dev, enc);
  4979. if (IS_ERR_OR_NULL(bridge)) {
  4980. rc = PTR_ERR(bridge);
  4981. DSI_ERR("[%s] brige init failed, %d\n", display->name, rc);
  4982. goto error;
  4983. }
  4984. display->bridge = bridge;
  4985. priv->bridges[priv->num_bridges++] = &bridge->base;
  4986. error:
  4987. mutex_unlock(&display->display_lock);
  4988. return rc;
  4989. }
  4990. int dsi_display_drm_bridge_deinit(struct dsi_display *display)
  4991. {
  4992. int rc = 0;
  4993. if (!display) {
  4994. DSI_ERR("Invalid params\n");
  4995. return -EINVAL;
  4996. }
  4997. mutex_lock(&display->display_lock);
  4998. dsi_drm_bridge_cleanup(display->bridge);
  4999. display->bridge = NULL;
  5000. mutex_unlock(&display->display_lock);
  5001. return rc;
  5002. }
  5003. /* Hook functions to call external connector, pointer validation is
  5004. * done in dsi_display_drm_ext_bridge_init.
  5005. */
  5006. static enum drm_connector_status dsi_display_drm_ext_detect(
  5007. struct drm_connector *connector,
  5008. bool force,
  5009. void *disp)
  5010. {
  5011. struct dsi_display *display = disp;
  5012. return display->ext_conn->funcs->detect(display->ext_conn, force);
  5013. }
  5014. static int dsi_display_drm_ext_get_modes(
  5015. struct drm_connector *connector, void *disp,
  5016. const struct msm_resource_caps_info *avail_res)
  5017. {
  5018. struct dsi_display *display = disp;
  5019. struct drm_display_mode *pmode, *pt;
  5020. int count;
  5021. /* if there are modes defined in panel, ignore external modes */
  5022. if (display->panel->num_timing_nodes)
  5023. return dsi_connector_get_modes(connector, disp, avail_res);
  5024. count = display->ext_conn->helper_private->get_modes(
  5025. display->ext_conn);
  5026. list_for_each_entry_safe(pmode, pt,
  5027. &display->ext_conn->probed_modes, head) {
  5028. list_move_tail(&pmode->head, &connector->probed_modes);
  5029. }
  5030. connector->display_info = display->ext_conn->display_info;
  5031. return count;
  5032. }
  5033. static enum drm_mode_status dsi_display_drm_ext_mode_valid(
  5034. struct drm_connector *connector,
  5035. struct drm_display_mode *mode,
  5036. void *disp, const struct msm_resource_caps_info *avail_res)
  5037. {
  5038. struct dsi_display *display = disp;
  5039. enum drm_mode_status status;
  5040. /* always do internal mode_valid check */
  5041. status = dsi_conn_mode_valid(connector, mode, disp, avail_res);
  5042. if (status != MODE_OK)
  5043. return status;
  5044. return display->ext_conn->helper_private->mode_valid(
  5045. display->ext_conn, mode);
  5046. }
  5047. static int dsi_display_drm_ext_atomic_check(struct drm_connector *connector,
  5048. void *disp,
  5049. struct drm_atomic_state *state)
  5050. {
  5051. struct dsi_display *display = disp;
  5052. struct drm_connector_state *c_state;
  5053. c_state = drm_atomic_get_new_connector_state(state, connector);
  5054. return display->ext_conn->helper_private->atomic_check(
  5055. display->ext_conn, state);
  5056. }
  5057. static int dsi_display_ext_get_info(struct drm_connector *connector,
  5058. struct msm_display_info *info, void *disp)
  5059. {
  5060. struct dsi_display *display;
  5061. int i;
  5062. if (!info || !disp) {
  5063. DSI_ERR("invalid params\n");
  5064. return -EINVAL;
  5065. }
  5066. display = disp;
  5067. if (!display->panel) {
  5068. DSI_ERR("invalid display panel\n");
  5069. return -EINVAL;
  5070. }
  5071. mutex_lock(&display->display_lock);
  5072. memset(info, 0, sizeof(struct msm_display_info));
  5073. info->intf_type = DRM_MODE_CONNECTOR_DSI;
  5074. info->num_of_h_tiles = display->ctrl_count;
  5075. for (i = 0; i < info->num_of_h_tiles; i++)
  5076. info->h_tile_instance[i] = display->ctrl[i].ctrl->cell_index;
  5077. info->is_connected = connector->status != connector_status_disconnected;
  5078. if (!strcmp(display->display_type, "primary"))
  5079. info->display_type = SDE_CONNECTOR_PRIMARY;
  5080. else if (!strcmp(display->display_type, "secondary"))
  5081. info->display_type = SDE_CONNECTOR_SECONDARY;
  5082. info->capabilities |= (MSM_DISPLAY_CAP_VID_MODE |
  5083. MSM_DISPLAY_CAP_EDID | MSM_DISPLAY_CAP_HOT_PLUG);
  5084. info->curr_panel_mode = MSM_DISPLAY_VIDEO_MODE;
  5085. mutex_unlock(&display->display_lock);
  5086. return 0;
  5087. }
  5088. static int dsi_display_ext_get_mode_info(struct drm_connector *connector,
  5089. const struct drm_display_mode *drm_mode,
  5090. struct msm_mode_info *mode_info,
  5091. void *display, const struct msm_resource_caps_info *avail_res)
  5092. {
  5093. struct msm_display_topology *topology;
  5094. if (!drm_mode || !mode_info ||
  5095. !avail_res || !avail_res->max_mixer_width)
  5096. return -EINVAL;
  5097. memset(mode_info, 0, sizeof(*mode_info));
  5098. mode_info->frame_rate = drm_mode_vrefresh(drm_mode);
  5099. mode_info->vtotal = drm_mode->vtotal;
  5100. topology = &mode_info->topology;
  5101. topology->num_lm = (avail_res->max_mixer_width
  5102. <= drm_mode->hdisplay) ? 2 : 1;
  5103. topology->num_enc = 0;
  5104. topology->num_intf = topology->num_lm;
  5105. mode_info->comp_info.comp_type = MSM_DISPLAY_COMPRESSION_NONE;
  5106. return 0;
  5107. }
  5108. static struct dsi_display_ext_bridge *dsi_display_ext_get_bridge(
  5109. struct drm_bridge *bridge)
  5110. {
  5111. struct msm_drm_private *priv;
  5112. struct sde_kms *sde_kms;
  5113. struct drm_connector *conn;
  5114. struct drm_connector_list_iter conn_iter;
  5115. struct sde_connector *sde_conn;
  5116. struct dsi_display *display;
  5117. struct dsi_display_ext_bridge *dsi_bridge = NULL;
  5118. int i;
  5119. if (!bridge || !bridge->encoder) {
  5120. SDE_ERROR("invalid argument\n");
  5121. return NULL;
  5122. }
  5123. priv = bridge->dev->dev_private;
  5124. sde_kms = to_sde_kms(priv->kms);
  5125. drm_connector_list_iter_begin(sde_kms->dev, &conn_iter);
  5126. drm_for_each_connector_iter(conn, &conn_iter) {
  5127. sde_conn = to_sde_connector(conn);
  5128. if (sde_conn->encoder == bridge->encoder) {
  5129. display = sde_conn->display;
  5130. display_for_each_ctrl(i, display) {
  5131. if (display->ext_bridge[i].bridge == bridge) {
  5132. dsi_bridge = &display->ext_bridge[i];
  5133. break;
  5134. }
  5135. }
  5136. }
  5137. }
  5138. drm_connector_list_iter_end(&conn_iter);
  5139. return dsi_bridge;
  5140. }
  5141. static void dsi_display_drm_ext_adjust_timing(
  5142. const struct dsi_display *display,
  5143. struct drm_display_mode *mode)
  5144. {
  5145. mode->hdisplay /= display->ctrl_count;
  5146. mode->hsync_start /= display->ctrl_count;
  5147. mode->hsync_end /= display->ctrl_count;
  5148. mode->htotal /= display->ctrl_count;
  5149. mode->hskew /= display->ctrl_count;
  5150. mode->clock /= display->ctrl_count;
  5151. }
  5152. static enum drm_mode_status dsi_display_drm_ext_bridge_mode_valid(
  5153. struct drm_bridge *bridge,
  5154. const struct drm_display_info *info,
  5155. const struct drm_display_mode *mode)
  5156. {
  5157. struct dsi_display_ext_bridge *ext_bridge;
  5158. struct drm_display_mode tmp;
  5159. ext_bridge = dsi_display_ext_get_bridge(bridge);
  5160. if (!ext_bridge)
  5161. return MODE_ERROR;
  5162. tmp = *mode;
  5163. dsi_display_drm_ext_adjust_timing(ext_bridge->display, &tmp);
  5164. return ext_bridge->orig_funcs->mode_valid(bridge, info, &tmp);
  5165. }
  5166. static bool dsi_display_drm_ext_bridge_mode_fixup(
  5167. struct drm_bridge *bridge,
  5168. const struct drm_display_mode *mode,
  5169. struct drm_display_mode *adjusted_mode)
  5170. {
  5171. struct dsi_display_ext_bridge *ext_bridge;
  5172. struct drm_display_mode tmp;
  5173. ext_bridge = dsi_display_ext_get_bridge(bridge);
  5174. if (!ext_bridge)
  5175. return false;
  5176. tmp = *mode;
  5177. dsi_display_drm_ext_adjust_timing(ext_bridge->display, &tmp);
  5178. return ext_bridge->orig_funcs->mode_fixup(bridge, &tmp, &tmp);
  5179. }
  5180. static void dsi_display_drm_ext_bridge_mode_set(
  5181. struct drm_bridge *bridge,
  5182. const struct drm_display_mode *mode,
  5183. const struct drm_display_mode *adjusted_mode)
  5184. {
  5185. struct dsi_display_ext_bridge *ext_bridge;
  5186. struct drm_display_mode tmp;
  5187. ext_bridge = dsi_display_ext_get_bridge(bridge);
  5188. if (!ext_bridge)
  5189. return;
  5190. tmp = *mode;
  5191. dsi_display_drm_ext_adjust_timing(ext_bridge->display, &tmp);
  5192. ext_bridge->orig_funcs->mode_set(bridge, &tmp, &tmp);
  5193. }
  5194. static int dsi_host_ext_attach(struct mipi_dsi_host *host,
  5195. struct mipi_dsi_device *dsi)
  5196. {
  5197. struct dsi_display *display = to_dsi_display(host);
  5198. struct dsi_panel *panel;
  5199. if (!host || !dsi || !display->panel) {
  5200. DSI_ERR("Invalid param\n");
  5201. return -EINVAL;
  5202. }
  5203. DSI_DEBUG("DSI[%s]: channel=%d, lanes=%d, format=%d, mode_flags=%lx\n",
  5204. dsi->name, dsi->channel, dsi->lanes,
  5205. dsi->format, dsi->mode_flags);
  5206. panel = display->panel;
  5207. panel->host_config.data_lanes = 0;
  5208. if (dsi->lanes > 0)
  5209. panel->host_config.data_lanes |= DSI_DATA_LANE_0;
  5210. if (dsi->lanes > 1)
  5211. panel->host_config.data_lanes |= DSI_DATA_LANE_1;
  5212. if (dsi->lanes > 2)
  5213. panel->host_config.data_lanes |= DSI_DATA_LANE_2;
  5214. if (dsi->lanes > 3)
  5215. panel->host_config.data_lanes |= DSI_DATA_LANE_3;
  5216. switch (dsi->format) {
  5217. case MIPI_DSI_FMT_RGB888:
  5218. panel->host_config.dst_format = DSI_PIXEL_FORMAT_RGB888;
  5219. break;
  5220. case MIPI_DSI_FMT_RGB666:
  5221. panel->host_config.dst_format = DSI_PIXEL_FORMAT_RGB666_LOOSE;
  5222. break;
  5223. case MIPI_DSI_FMT_RGB666_PACKED:
  5224. panel->host_config.dst_format = DSI_PIXEL_FORMAT_RGB666;
  5225. break;
  5226. case MIPI_DSI_FMT_RGB565:
  5227. default:
  5228. panel->host_config.dst_format = DSI_PIXEL_FORMAT_RGB565;
  5229. break;
  5230. }
  5231. if (dsi->mode_flags & MIPI_DSI_MODE_VIDEO) {
  5232. panel->panel_mode = DSI_OP_VIDEO_MODE;
  5233. if (dsi->mode_flags & MIPI_DSI_MODE_VIDEO_BURST)
  5234. panel->video_config.traffic_mode =
  5235. DSI_VIDEO_TRAFFIC_BURST_MODE;
  5236. else if (dsi->mode_flags & MIPI_DSI_MODE_VIDEO_SYNC_PULSE)
  5237. panel->video_config.traffic_mode =
  5238. DSI_VIDEO_TRAFFIC_SYNC_PULSES;
  5239. else
  5240. panel->video_config.traffic_mode =
  5241. DSI_VIDEO_TRAFFIC_SYNC_START_EVENTS;
  5242. panel->video_config.hsa_lp11_en =
  5243. dsi->mode_flags & MIPI_DSI_MODE_VIDEO_HSA;
  5244. panel->video_config.hbp_lp11_en =
  5245. dsi->mode_flags & MIPI_DSI_MODE_VIDEO_HBP;
  5246. panel->video_config.hfp_lp11_en =
  5247. dsi->mode_flags & MIPI_DSI_MODE_VIDEO_HFP;
  5248. panel->video_config.pulse_mode_hsa_he =
  5249. dsi->mode_flags & MIPI_DSI_MODE_VIDEO_HSE;
  5250. } else {
  5251. panel->panel_mode = DSI_OP_CMD_MODE;
  5252. DSI_ERR("command mode not supported by ext bridge\n");
  5253. return -ENOTSUPP;
  5254. }
  5255. panel->bl_config.type = DSI_BACKLIGHT_UNKNOWN;
  5256. return 0;
  5257. }
  5258. static struct mipi_dsi_host_ops dsi_host_ext_ops = {
  5259. .attach = dsi_host_ext_attach,
  5260. .detach = dsi_host_detach,
  5261. .transfer = dsi_host_transfer,
  5262. };
  5263. struct drm_panel *dsi_display_get_drm_panel(struct dsi_display *display)
  5264. {
  5265. if (!display || !display->panel) {
  5266. pr_err("invalid param(s)\n");
  5267. return NULL;
  5268. }
  5269. return &display->panel->drm_panel;
  5270. }
  5271. int dsi_display_drm_ext_bridge_init(struct dsi_display *display,
  5272. struct drm_encoder *encoder, struct drm_connector *connector)
  5273. {
  5274. struct drm_device *drm;
  5275. struct drm_bridge *bridge;
  5276. struct drm_bridge *ext_bridge;
  5277. struct drm_connector *ext_conn;
  5278. struct sde_connector *sde_conn;
  5279. struct drm_bridge *prev_bridge;
  5280. int rc = 0, i;
  5281. if (!display || !encoder || !connector)
  5282. return -EINVAL;
  5283. drm = encoder->dev;
  5284. bridge = drm_bridge_chain_get_first_bridge(encoder);
  5285. sde_conn = to_sde_connector(connector);
  5286. prev_bridge = bridge;
  5287. if (display->panel && !display->panel->host_config.ext_bridge_mode)
  5288. return 0;
  5289. for (i = 0; i < display->ext_bridge_cnt; i++) {
  5290. struct dsi_display_ext_bridge *ext_bridge_info =
  5291. &display->ext_bridge[i];
  5292. struct drm_encoder *c_encoder;
  5293. /* return if ext bridge is already initialized */
  5294. if (ext_bridge_info->bridge)
  5295. return 0;
  5296. ext_bridge = of_drm_find_bridge(ext_bridge_info->node_of);
  5297. if (IS_ERR_OR_NULL(ext_bridge)) {
  5298. rc = PTR_ERR(ext_bridge);
  5299. DSI_ERR("failed to find ext bridge\n");
  5300. goto error;
  5301. }
  5302. /* override functions for mode adjustment */
  5303. if (display->ext_bridge_cnt > 1) {
  5304. ext_bridge_info->bridge_funcs = *ext_bridge->funcs;
  5305. if (ext_bridge->funcs->mode_fixup)
  5306. ext_bridge_info->bridge_funcs.mode_fixup =
  5307. dsi_display_drm_ext_bridge_mode_fixup;
  5308. if (ext_bridge->funcs->mode_valid)
  5309. ext_bridge_info->bridge_funcs.mode_valid =
  5310. dsi_display_drm_ext_bridge_mode_valid;
  5311. if (ext_bridge->funcs->mode_set)
  5312. ext_bridge_info->bridge_funcs.mode_set =
  5313. dsi_display_drm_ext_bridge_mode_set;
  5314. ext_bridge_info->orig_funcs = ext_bridge->funcs;
  5315. ext_bridge->funcs = &ext_bridge_info->bridge_funcs;
  5316. }
  5317. rc = drm_bridge_attach(encoder, ext_bridge, prev_bridge, 0);
  5318. if (rc) {
  5319. DSI_ERR("[%s] ext brige attach failed, %d\n",
  5320. display->name, rc);
  5321. goto error;
  5322. }
  5323. ext_bridge_info->display = display;
  5324. ext_bridge_info->bridge = ext_bridge;
  5325. prev_bridge = ext_bridge;
  5326. /* ext bridge will init its own connector during attach,
  5327. * we need to extract it out of the connector list
  5328. */
  5329. spin_lock_irq(&drm->mode_config.connector_list_lock);
  5330. ext_conn = list_last_entry(&drm->mode_config.connector_list,
  5331. struct drm_connector, head);
  5332. drm_connector_for_each_possible_encoder(ext_conn, c_encoder)
  5333. break;
  5334. if (!c_encoder) {
  5335. DSI_ERR("failed to get encoder\n");
  5336. rc = PTR_ERR(c_encoder);
  5337. spin_unlock_irq(&drm->mode_config.connector_list_lock);
  5338. goto error;
  5339. }
  5340. if (ext_conn && ext_conn != connector &&
  5341. c_encoder->base.id == bridge->encoder->base.id) {
  5342. list_del_init(&ext_conn->head);
  5343. display->ext_conn = ext_conn;
  5344. }
  5345. spin_unlock_irq(&drm->mode_config.connector_list_lock);
  5346. /* if there is no valid external connector created, or in split
  5347. * mode, default setting is used from panel defined in DT file.
  5348. */
  5349. if (!display->ext_conn ||
  5350. !display->ext_conn->funcs ||
  5351. !display->ext_conn->helper_private ||
  5352. display->ext_bridge_cnt > 1) {
  5353. display->ext_conn = NULL;
  5354. continue;
  5355. }
  5356. /* otherwise, hook up the functions to use external connector */
  5357. if (display->ext_conn->funcs->detect)
  5358. sde_conn->ops.detect = dsi_display_drm_ext_detect;
  5359. if (display->ext_conn->helper_private->get_modes)
  5360. sde_conn->ops.get_modes =
  5361. dsi_display_drm_ext_get_modes;
  5362. if (display->ext_conn->helper_private->mode_valid)
  5363. sde_conn->ops.mode_valid =
  5364. dsi_display_drm_ext_mode_valid;
  5365. if (display->ext_conn->helper_private->atomic_check)
  5366. sde_conn->ops.atomic_check =
  5367. dsi_display_drm_ext_atomic_check;
  5368. sde_conn->ops.get_info =
  5369. dsi_display_ext_get_info;
  5370. sde_conn->ops.get_mode_info =
  5371. dsi_display_ext_get_mode_info;
  5372. /* add support to attach/detach */
  5373. display->host.ops = &dsi_host_ext_ops;
  5374. }
  5375. return 0;
  5376. error:
  5377. return rc;
  5378. }
  5379. int dsi_display_get_info(struct drm_connector *connector,
  5380. struct msm_display_info *info, void *disp)
  5381. {
  5382. struct dsi_display *display;
  5383. struct dsi_panel_phy_props phy_props;
  5384. struct dsi_host_common_cfg *host;
  5385. int i, rc;
  5386. if (!info || !disp) {
  5387. DSI_ERR("invalid params\n");
  5388. return -EINVAL;
  5389. }
  5390. display = disp;
  5391. if (!display->panel) {
  5392. DSI_ERR("invalid display panel\n");
  5393. return -EINVAL;
  5394. }
  5395. mutex_lock(&display->display_lock);
  5396. rc = dsi_panel_get_phy_props(display->panel, &phy_props);
  5397. if (rc) {
  5398. DSI_ERR("[%s] failed to get panel phy props, rc=%d\n",
  5399. display->name, rc);
  5400. goto error;
  5401. }
  5402. memset(info, 0, sizeof(struct msm_display_info));
  5403. info->intf_type = DRM_MODE_CONNECTOR_DSI;
  5404. info->num_of_h_tiles = display->ctrl_count;
  5405. for (i = 0; i < info->num_of_h_tiles; i++)
  5406. info->h_tile_instance[i] = display->ctrl[i].ctrl->cell_index;
  5407. info->is_connected = display->is_active;
  5408. if (!strcmp(display->display_type, "primary"))
  5409. info->display_type = SDE_CONNECTOR_PRIMARY;
  5410. else if (!strcmp(display->display_type, "secondary"))
  5411. info->display_type = SDE_CONNECTOR_SECONDARY;
  5412. info->width_mm = phy_props.panel_width_mm;
  5413. info->height_mm = phy_props.panel_height_mm;
  5414. info->max_width = 1920;
  5415. info->max_height = 1080;
  5416. info->qsync_min_fps =
  5417. display->panel->qsync_caps.qsync_min_fps;
  5418. info->has_qsync_min_fps_list =
  5419. (display->panel->qsync_caps.qsync_min_fps_list_len > 0) ?
  5420. true : false;
  5421. info->poms_align_vsync = display->panel->poms_align_vsync;
  5422. switch (display->panel->panel_mode) {
  5423. case DSI_OP_VIDEO_MODE:
  5424. info->curr_panel_mode = MSM_DISPLAY_VIDEO_MODE;
  5425. info->capabilities |= MSM_DISPLAY_CAP_VID_MODE;
  5426. if (display->panel->panel_mode_switch_enabled)
  5427. info->capabilities |= MSM_DISPLAY_CAP_CMD_MODE;
  5428. break;
  5429. case DSI_OP_CMD_MODE:
  5430. info->curr_panel_mode = MSM_DISPLAY_CMD_MODE;
  5431. info->capabilities |= MSM_DISPLAY_CAP_CMD_MODE;
  5432. if (display->panel->panel_mode_switch_enabled)
  5433. info->capabilities |= MSM_DISPLAY_CAP_VID_MODE;
  5434. info->is_te_using_watchdog_timer =
  5435. display->panel->te_using_watchdog_timer |
  5436. display->sw_te_using_wd;
  5437. break;
  5438. default:
  5439. DSI_ERR("unknwown dsi panel mode %d\n",
  5440. display->panel->panel_mode);
  5441. break;
  5442. }
  5443. if (display->panel->esd_config.esd_enabled &&
  5444. !display->sw_te_using_wd)
  5445. info->capabilities |= MSM_DISPLAY_ESD_ENABLED;
  5446. info->te_source = display->te_source;
  5447. host = &display->panel->host_config;
  5448. if (host->split_link.split_link_enabled)
  5449. info->capabilities |= MSM_DISPLAY_SPLIT_LINK;
  5450. info->dsc_count = display->panel->dsc_count;
  5451. info->lm_count = display->panel->lm_count;
  5452. error:
  5453. mutex_unlock(&display->display_lock);
  5454. return rc;
  5455. }
  5456. int dsi_display_get_mode_count(struct dsi_display *display,
  5457. u32 *count)
  5458. {
  5459. if (!display || !display->panel) {
  5460. DSI_ERR("invalid display:%d panel:%d\n", display != NULL,
  5461. display ? display->panel != NULL : 0);
  5462. return -EINVAL;
  5463. }
  5464. mutex_lock(&display->display_lock);
  5465. *count = display->panel->num_display_modes;
  5466. mutex_unlock(&display->display_lock);
  5467. return 0;
  5468. }
  5469. void dsi_display_adjust_mode_timing(struct dsi_display *display,
  5470. struct dsi_display_mode *dsi_mode,
  5471. int lanes, int bpp)
  5472. {
  5473. u64 new_htotal, new_vtotal, htotal, vtotal, old_htotal, div;
  5474. struct dsi_dyn_clk_caps *dyn_clk_caps;
  5475. u32 bits_per_symbol = 16, num_of_symbols = 7; /* For Cphy */
  5476. dyn_clk_caps = &(display->panel->dyn_clk_caps);
  5477. /* Constant FPS is not supported on command mode */
  5478. if (!(dsi_mode->panel_mode_caps & DSI_OP_VIDEO_MODE))
  5479. return;
  5480. if (!dyn_clk_caps->maintain_const_fps)
  5481. return;
  5482. /*
  5483. * When there is a dynamic clock switch, there is small change
  5484. * in FPS. To compensate for this difference in FPS, hfp or vfp
  5485. * is adjusted. It has been assumed that the refined porch values
  5486. * are supported by the panel. This logic can be enhanced further
  5487. * in future by taking min/max porches supported by the panel.
  5488. */
  5489. switch (dyn_clk_caps->type) {
  5490. case DSI_DYN_CLK_TYPE_CONST_FPS_ADJUST_HFP:
  5491. vtotal = DSI_V_TOTAL(&dsi_mode->timing);
  5492. old_htotal = dsi_h_total_dce(&dsi_mode->timing);
  5493. do_div(old_htotal, display->ctrl_count);
  5494. new_htotal = dsi_mode->timing.clk_rate_hz * lanes;
  5495. div = bpp * vtotal * dsi_mode->timing.refresh_rate;
  5496. if (dsi_display_is_type_cphy(display)) {
  5497. new_htotal = new_htotal * bits_per_symbol;
  5498. div = div * num_of_symbols;
  5499. }
  5500. do_div(new_htotal, div);
  5501. if (old_htotal > new_htotal)
  5502. dsi_mode->timing.h_front_porch -=
  5503. ((old_htotal - new_htotal) * display->ctrl_count);
  5504. else
  5505. dsi_mode->timing.h_front_porch +=
  5506. ((new_htotal - old_htotal) * display->ctrl_count);
  5507. break;
  5508. case DSI_DYN_CLK_TYPE_CONST_FPS_ADJUST_VFP:
  5509. htotal = dsi_h_total_dce(&dsi_mode->timing);
  5510. do_div(htotal, display->ctrl_count);
  5511. new_vtotal = dsi_mode->timing.clk_rate_hz * lanes;
  5512. div = bpp * htotal * dsi_mode->timing.refresh_rate;
  5513. if (dsi_display_is_type_cphy(display)) {
  5514. new_vtotal = new_vtotal * bits_per_symbol;
  5515. div = div * num_of_symbols;
  5516. }
  5517. do_div(new_vtotal, div);
  5518. dsi_mode->timing.v_front_porch = new_vtotal -
  5519. dsi_mode->timing.v_back_porch -
  5520. dsi_mode->timing.v_sync_width -
  5521. dsi_mode->timing.v_active;
  5522. break;
  5523. default:
  5524. break;
  5525. }
  5526. }
  5527. static void _dsi_display_populate_bit_clks(struct dsi_display *display,
  5528. int start, int end, u32 *mode_idx)
  5529. {
  5530. struct dsi_dyn_clk_caps *dyn_clk_caps;
  5531. struct dsi_display_mode *src, *dst;
  5532. struct dsi_host_common_cfg *cfg;
  5533. struct dsi_display_mode_priv_info *priv_info;
  5534. int i, j, total_modes, bpp, lanes = 0;
  5535. size_t size = 0;
  5536. if (!display || !mode_idx)
  5537. return;
  5538. dyn_clk_caps = &(display->panel->dyn_clk_caps);
  5539. if (!dyn_clk_caps->dyn_clk_support)
  5540. return;
  5541. cfg = &(display->panel->host_config);
  5542. bpp = dsi_pixel_format_to_bpp(cfg->dst_format);
  5543. if (cfg->data_lanes & DSI_DATA_LANE_0)
  5544. lanes++;
  5545. if (cfg->data_lanes & DSI_DATA_LANE_1)
  5546. lanes++;
  5547. if (cfg->data_lanes & DSI_DATA_LANE_2)
  5548. lanes++;
  5549. if (cfg->data_lanes & DSI_DATA_LANE_3)
  5550. lanes++;
  5551. total_modes = display->panel->num_display_modes;
  5552. for (i = start; i < end; i++) {
  5553. src = &display->modes[i];
  5554. if (!src)
  5555. return;
  5556. /*
  5557. * TODO: currently setting the first bit rate in
  5558. * the list as preferred rate. But ideally should
  5559. * be based on user or device tree preferrence.
  5560. */
  5561. src->timing.clk_rate_hz = dyn_clk_caps->bit_clk_list[0];
  5562. dsi_display_adjust_mode_timing(display, src, lanes, bpp);
  5563. src->pixel_clk_khz =
  5564. div_u64(src->timing.clk_rate_hz * lanes, bpp);
  5565. src->pixel_clk_khz /= 1000;
  5566. src->pixel_clk_khz *= display->ctrl_count;
  5567. }
  5568. for (i = 1; i < dyn_clk_caps->bit_clk_list_len; i++) {
  5569. if (*mode_idx >= total_modes)
  5570. return;
  5571. for (j = start; j < end; j++) {
  5572. src = &display->modes[j];
  5573. dst = &display->modes[*mode_idx];
  5574. if (!src || !dst) {
  5575. DSI_ERR("invalid mode index\n");
  5576. return;
  5577. }
  5578. memcpy(dst, src, sizeof(struct dsi_display_mode));
  5579. size = sizeof(struct dsi_display_mode_priv_info);
  5580. priv_info = kzalloc(size, GFP_KERNEL);
  5581. dst->priv_info = priv_info;
  5582. if (dst->priv_info)
  5583. memcpy(dst->priv_info, src->priv_info, size);
  5584. dst->timing.clk_rate_hz = dyn_clk_caps->bit_clk_list[i];
  5585. dsi_display_adjust_mode_timing(display, dst, lanes,
  5586. bpp);
  5587. dst->panel_mode_caps = DSI_OP_VIDEO_MODE;
  5588. dst->pixel_clk_khz =
  5589. div_u64(dst->timing.clk_rate_hz * lanes, bpp);
  5590. dst->pixel_clk_khz /= 1000;
  5591. dst->pixel_clk_khz *= display->ctrl_count;
  5592. (*mode_idx)++;
  5593. }
  5594. }
  5595. }
  5596. void dsi_display_put_mode(struct dsi_display *display,
  5597. struct dsi_display_mode *mode)
  5598. {
  5599. dsi_panel_put_mode(mode);
  5600. }
  5601. int dsi_display_get_modes(struct dsi_display *display,
  5602. struct dsi_display_mode **out_modes)
  5603. {
  5604. struct dsi_dfps_capabilities dfps_caps;
  5605. struct dsi_display_ctrl *ctrl;
  5606. struct dsi_host_common_cfg *host = &display->panel->host_config;
  5607. bool is_split_link, support_cmd_mode, support_video_mode;
  5608. u32 num_dfps_rates, timing_mode_count, display_mode_count;
  5609. u32 sublinks_count, mode_idx, array_idx = 0;
  5610. struct dsi_dyn_clk_caps *dyn_clk_caps;
  5611. int i, start, end, rc = -EINVAL;
  5612. if (!display || !out_modes) {
  5613. DSI_ERR("Invalid params\n");
  5614. return -EINVAL;
  5615. }
  5616. *out_modes = NULL;
  5617. ctrl = &display->ctrl[0];
  5618. mutex_lock(&display->display_lock);
  5619. if (display->modes)
  5620. goto exit;
  5621. display_mode_count = display->panel->num_display_modes;
  5622. display->modes = kcalloc(display_mode_count, sizeof(*display->modes),
  5623. GFP_KERNEL);
  5624. if (!display->modes) {
  5625. rc = -ENOMEM;
  5626. goto error;
  5627. }
  5628. rc = dsi_panel_get_dfps_caps(display->panel, &dfps_caps);
  5629. if (rc) {
  5630. DSI_ERR("[%s] failed to get dfps caps from panel\n",
  5631. display->name);
  5632. goto error;
  5633. }
  5634. dyn_clk_caps = &(display->panel->dyn_clk_caps);
  5635. timing_mode_count = display->panel->num_timing_nodes;
  5636. /* Validate command line timing */
  5637. if ((display->cmdline_timing != NO_OVERRIDE) &&
  5638. (display->cmdline_timing >= timing_mode_count))
  5639. display->cmdline_timing = NO_OVERRIDE;
  5640. for (mode_idx = 0; mode_idx < timing_mode_count; mode_idx++) {
  5641. struct dsi_display_mode display_mode;
  5642. int topology_override = NO_OVERRIDE;
  5643. bool is_preferred = false;
  5644. u32 frame_threshold_us = ctrl->ctrl->frame_threshold_time_us;
  5645. if (display->cmdline_timing == mode_idx) {
  5646. topology_override = display->cmdline_topology;
  5647. is_preferred = true;
  5648. }
  5649. memset(&display_mode, 0, sizeof(display_mode));
  5650. rc = dsi_panel_get_mode(display->panel, mode_idx,
  5651. &display_mode,
  5652. topology_override);
  5653. if (rc) {
  5654. DSI_ERR("[%s] failed to get mode idx %d from panel\n",
  5655. display->name, mode_idx);
  5656. goto error;
  5657. }
  5658. support_cmd_mode = display_mode.panel_mode_caps & DSI_OP_CMD_MODE;
  5659. support_video_mode = display_mode.panel_mode_caps & DSI_OP_VIDEO_MODE;
  5660. /* Setup widebus support */
  5661. display_mode.priv_info->widebus_support =
  5662. ctrl->ctrl->hw.widebus_support;
  5663. num_dfps_rates = ((!dfps_caps.dfps_support ||
  5664. !support_video_mode) ? 1 : dfps_caps.dfps_list_len);
  5665. /* Calculate dsi frame transfer time */
  5666. if (support_cmd_mode) {
  5667. dsi_panel_calc_dsi_transfer_time(
  5668. &display->panel->host_config,
  5669. &display_mode, frame_threshold_us);
  5670. display_mode.priv_info->dsi_transfer_time_us =
  5671. display_mode.timing.dsi_transfer_time_us;
  5672. display_mode.priv_info->min_dsi_clk_hz =
  5673. display_mode.timing.min_dsi_clk_hz;
  5674. display_mode.priv_info->mdp_transfer_time_us =
  5675. display_mode.timing.mdp_transfer_time_us;
  5676. }
  5677. is_split_link = host->split_link.split_link_enabled;
  5678. sublinks_count = host->split_link.num_sublinks;
  5679. if (is_split_link && sublinks_count > 1) {
  5680. display_mode.timing.h_active *= sublinks_count;
  5681. display_mode.timing.h_front_porch *= sublinks_count;
  5682. display_mode.timing.h_sync_width *= sublinks_count;
  5683. display_mode.timing.h_back_porch *= sublinks_count;
  5684. display_mode.timing.h_skew *= sublinks_count;
  5685. display_mode.pixel_clk_khz *= sublinks_count;
  5686. } else {
  5687. display_mode.timing.h_active *= display->ctrl_count;
  5688. display_mode.timing.h_front_porch *=
  5689. display->ctrl_count;
  5690. display_mode.timing.h_sync_width *=
  5691. display->ctrl_count;
  5692. display_mode.timing.h_back_porch *=
  5693. display->ctrl_count;
  5694. display_mode.timing.h_skew *= display->ctrl_count;
  5695. display_mode.pixel_clk_khz *= display->ctrl_count;
  5696. }
  5697. start = array_idx;
  5698. for (i = 0; i < num_dfps_rates; i++) {
  5699. struct dsi_display_mode *sub_mode =
  5700. &display->modes[array_idx];
  5701. u32 curr_refresh_rate;
  5702. if (!sub_mode) {
  5703. DSI_ERR("invalid mode data\n");
  5704. rc = -EFAULT;
  5705. goto error;
  5706. }
  5707. memcpy(sub_mode, &display_mode, sizeof(display_mode));
  5708. array_idx++;
  5709. if (!dfps_caps.dfps_support || !support_video_mode)
  5710. continue;
  5711. curr_refresh_rate = sub_mode->timing.refresh_rate;
  5712. sub_mode->timing.refresh_rate = dfps_caps.dfps_list[i];
  5713. dsi_display_get_dfps_timing(display, sub_mode,
  5714. curr_refresh_rate);
  5715. sub_mode->panel_mode_caps = DSI_OP_VIDEO_MODE;
  5716. }
  5717. end = array_idx;
  5718. _dsi_display_populate_bit_clks(display, start, end, &array_idx);
  5719. if (is_preferred) {
  5720. /* Set first timing sub mode as preferred mode */
  5721. display->modes[start].is_preferred = true;
  5722. }
  5723. }
  5724. exit:
  5725. *out_modes = display->modes;
  5726. rc = 0;
  5727. error:
  5728. if (rc)
  5729. kfree(display->modes);
  5730. mutex_unlock(&display->display_lock);
  5731. return rc;
  5732. }
  5733. int dsi_display_get_panel_vfp(void *dsi_display,
  5734. int h_active, int v_active)
  5735. {
  5736. int i, rc = 0;
  5737. u32 count, refresh_rate = 0;
  5738. struct dsi_dfps_capabilities dfps_caps;
  5739. struct dsi_display *display = (struct dsi_display *)dsi_display;
  5740. struct dsi_host_common_cfg *host;
  5741. if (!display || !display->panel)
  5742. return -EINVAL;
  5743. mutex_lock(&display->display_lock);
  5744. count = display->panel->num_display_modes;
  5745. if (display->panel->cur_mode)
  5746. refresh_rate = display->panel->cur_mode->timing.refresh_rate;
  5747. dsi_panel_get_dfps_caps(display->panel, &dfps_caps);
  5748. if (dfps_caps.dfps_support)
  5749. refresh_rate = dfps_caps.max_refresh_rate;
  5750. if (!refresh_rate) {
  5751. mutex_unlock(&display->display_lock);
  5752. DSI_ERR("Null Refresh Rate\n");
  5753. return -EINVAL;
  5754. }
  5755. host = &display->panel->host_config;
  5756. if (host->split_link.split_link_enabled)
  5757. h_active *= host->split_link.num_sublinks;
  5758. else
  5759. h_active *= display->ctrl_count;
  5760. for (i = 0; i < count; i++) {
  5761. struct dsi_display_mode *m = &display->modes[i];
  5762. if (m && v_active == m->timing.v_active &&
  5763. h_active == m->timing.h_active &&
  5764. refresh_rate == m->timing.refresh_rate) {
  5765. rc = m->timing.v_front_porch;
  5766. break;
  5767. }
  5768. }
  5769. mutex_unlock(&display->display_lock);
  5770. return rc;
  5771. }
  5772. int dsi_display_get_default_lms(void *dsi_display, u32 *num_lm)
  5773. {
  5774. struct dsi_display *display = (struct dsi_display *)dsi_display;
  5775. u32 count, i;
  5776. int rc = 0;
  5777. *num_lm = 0;
  5778. mutex_lock(&display->display_lock);
  5779. count = display->panel->num_display_modes;
  5780. mutex_unlock(&display->display_lock);
  5781. if (!display->modes) {
  5782. struct dsi_display_mode *m;
  5783. rc = dsi_display_get_modes(display, &m);
  5784. if (rc)
  5785. return rc;
  5786. }
  5787. mutex_lock(&display->display_lock);
  5788. for (i = 0; i < count; i++) {
  5789. struct dsi_display_mode *m = &display->modes[i];
  5790. *num_lm = max(m->priv_info->topology.num_lm, *num_lm);
  5791. }
  5792. mutex_unlock(&display->display_lock);
  5793. return rc;
  5794. }
  5795. int dsi_display_get_qsync_min_fps(void *display_dsi, u32 mode_fps)
  5796. {
  5797. struct dsi_display *display = (struct dsi_display *)display_dsi;
  5798. struct dsi_panel *panel;
  5799. u32 i;
  5800. if (display == NULL || display->panel == NULL)
  5801. return -EINVAL;
  5802. panel = display->panel;
  5803. for (i = 0; i < panel->dfps_caps.dfps_list_len; i++) {
  5804. if (panel->dfps_caps.dfps_list[i] == mode_fps)
  5805. return panel->qsync_caps.qsync_min_fps_list[i];
  5806. }
  5807. SDE_EVT32(mode_fps);
  5808. DSI_DEBUG("Invalid mode_fps %d\n", mode_fps);
  5809. return -EINVAL;
  5810. }
  5811. int dsi_display_find_mode(struct dsi_display *display,
  5812. const struct dsi_display_mode *cmp,
  5813. struct dsi_display_mode **out_mode)
  5814. {
  5815. u32 count, i;
  5816. int rc;
  5817. if (!display || !out_mode)
  5818. return -EINVAL;
  5819. *out_mode = NULL;
  5820. mutex_lock(&display->display_lock);
  5821. count = display->panel->num_display_modes;
  5822. mutex_unlock(&display->display_lock);
  5823. if (!display->modes) {
  5824. struct dsi_display_mode *m;
  5825. rc = dsi_display_get_modes(display, &m);
  5826. if (rc)
  5827. return rc;
  5828. }
  5829. mutex_lock(&display->display_lock);
  5830. for (i = 0; i < count; i++) {
  5831. struct dsi_display_mode *m = &display->modes[i];
  5832. if (cmp->timing.v_active == m->timing.v_active &&
  5833. cmp->timing.h_active == m->timing.h_active &&
  5834. cmp->timing.refresh_rate == m->timing.refresh_rate) {
  5835. *out_mode = m;
  5836. rc = 0;
  5837. break;
  5838. }
  5839. }
  5840. mutex_unlock(&display->display_lock);
  5841. if (!*out_mode) {
  5842. DSI_ERR("[%s] failed to find mode for v_active %u h_active %u fps %u pclk %u\n",
  5843. display->name, cmp->timing.v_active,
  5844. cmp->timing.h_active, cmp->timing.refresh_rate,
  5845. cmp->pixel_clk_khz);
  5846. rc = -ENOENT;
  5847. }
  5848. return rc;
  5849. }
  5850. static inline bool dsi_display_mode_switch_dfps(struct dsi_display_mode *cur,
  5851. struct dsi_display_mode *adj)
  5852. {
  5853. /*
  5854. * If there is a change in the hfp or vfp of the current and adjoining
  5855. * mode,then either it is a dfps mode switch or dynamic clk change with
  5856. * constant fps.
  5857. */
  5858. if ((cur->timing.h_front_porch != adj->timing.h_front_porch) ||
  5859. (cur->timing.v_front_porch != adj->timing.v_front_porch))
  5860. return true;
  5861. else
  5862. return false;
  5863. }
  5864. /**
  5865. * dsi_display_validate_mode_change() - Validate mode change case.
  5866. * @display: DSI display handle.
  5867. * @cur_mode: Current mode.
  5868. * @adj_mode: Mode to be set.
  5869. * MSM_MODE_FLAG_SEAMLESS_VRR flag is set if there
  5870. * is change in hfp or vfp but vactive and hactive are same.
  5871. * DSI_MODE_FLAG_DYN_CLK flag is set if there
  5872. * is change in clk but vactive and hactive are same.
  5873. * Return: error code.
  5874. */
  5875. int dsi_display_validate_mode_change(struct dsi_display *display,
  5876. struct dsi_display_mode *cur_mode,
  5877. struct dsi_display_mode *adj_mode)
  5878. {
  5879. int rc = 0;
  5880. struct dsi_dfps_capabilities dfps_caps;
  5881. struct dsi_dyn_clk_caps *dyn_clk_caps;
  5882. struct sde_connector *sde_conn;
  5883. if (!display || !adj_mode || !display->drm_conn) {
  5884. DSI_ERR("Invalid params\n");
  5885. return -EINVAL;
  5886. }
  5887. if (!display->panel || !display->panel->cur_mode) {
  5888. DSI_DEBUG("Current panel mode not set\n");
  5889. return rc;
  5890. }
  5891. if ((cur_mode->timing.v_active != adj_mode->timing.v_active) ||
  5892. (cur_mode->timing.h_active != adj_mode->timing.h_active)) {
  5893. DSI_DEBUG("Avoid VRR and POMS when resolution is changed\n");
  5894. return rc;
  5895. }
  5896. sde_conn = to_sde_connector(display->drm_conn);
  5897. mutex_lock(&display->display_lock);
  5898. if (sde_conn->expected_panel_mode == MSM_DISPLAY_VIDEO_MODE &&
  5899. display->config.panel_mode == DSI_OP_CMD_MODE) {
  5900. adj_mode->dsi_mode_flags |= DSI_MODE_FLAG_POMS_TO_VID;
  5901. DSI_DEBUG("Panel operating mode change to video detected\n");
  5902. } else if (sde_conn->expected_panel_mode == MSM_DISPLAY_CMD_MODE &&
  5903. display->config.panel_mode == DSI_OP_VIDEO_MODE) {
  5904. adj_mode->dsi_mode_flags |= DSI_MODE_FLAG_POMS_TO_CMD;
  5905. DSI_DEBUG("Panel operating mode change to command detected\n");
  5906. } else {
  5907. dyn_clk_caps = &(display->panel->dyn_clk_caps);
  5908. /* dfps and dynamic clock with const fps use case */
  5909. if (dsi_display_mode_switch_dfps(cur_mode, adj_mode)) {
  5910. dsi_panel_get_dfps_caps(display->panel, &dfps_caps);
  5911. if (dfps_caps.dfps_support ||
  5912. dyn_clk_caps->maintain_const_fps) {
  5913. DSI_DEBUG("Mode switch is seamless variable refresh\n");
  5914. adj_mode->dsi_mode_flags |= DSI_MODE_FLAG_VRR;
  5915. SDE_EVT32(SDE_EVTLOG_FUNC_CASE1,
  5916. cur_mode->timing.refresh_rate,
  5917. adj_mode->timing.refresh_rate,
  5918. cur_mode->timing.h_front_porch,
  5919. adj_mode->timing.h_front_porch,
  5920. cur_mode->timing.v_front_porch,
  5921. adj_mode->timing.v_front_porch);
  5922. }
  5923. }
  5924. /* dynamic clk change use case */
  5925. if (cur_mode->pixel_clk_khz != adj_mode->pixel_clk_khz) {
  5926. if (dyn_clk_caps->dyn_clk_support) {
  5927. DSI_DEBUG("dynamic clk change detected\n");
  5928. if ((adj_mode->dsi_mode_flags &
  5929. DSI_MODE_FLAG_VRR) &&
  5930. (!dyn_clk_caps->maintain_const_fps)) {
  5931. DSI_ERR("dfps and dyn clk not supported in same commit\n");
  5932. rc = -ENOTSUPP;
  5933. goto error;
  5934. }
  5935. adj_mode->dsi_mode_flags |=
  5936. DSI_MODE_FLAG_DYN_CLK;
  5937. SDE_EVT32(SDE_EVTLOG_FUNC_CASE2,
  5938. cur_mode->pixel_clk_khz,
  5939. adj_mode->pixel_clk_khz);
  5940. }
  5941. }
  5942. }
  5943. error:
  5944. mutex_unlock(&display->display_lock);
  5945. return rc;
  5946. }
  5947. int dsi_display_validate_mode(struct dsi_display *display,
  5948. struct dsi_display_mode *mode,
  5949. u32 flags)
  5950. {
  5951. int rc = 0;
  5952. int i;
  5953. struct dsi_display_ctrl *ctrl;
  5954. struct dsi_display_mode adj_mode;
  5955. if (!display || !mode) {
  5956. DSI_ERR("Invalid params\n");
  5957. return -EINVAL;
  5958. }
  5959. mutex_lock(&display->display_lock);
  5960. adj_mode = *mode;
  5961. adjust_timing_by_ctrl_count(display, &adj_mode);
  5962. rc = dsi_panel_validate_mode(display->panel, &adj_mode);
  5963. if (rc) {
  5964. DSI_ERR("[%s] panel mode validation failed, rc=%d\n",
  5965. display->name, rc);
  5966. goto error;
  5967. }
  5968. display_for_each_ctrl(i, display) {
  5969. ctrl = &display->ctrl[i];
  5970. rc = dsi_ctrl_validate_timing(ctrl->ctrl, &adj_mode.timing);
  5971. if (rc) {
  5972. DSI_ERR("[%s] ctrl mode validation failed, rc=%d\n",
  5973. display->name, rc);
  5974. goto error;
  5975. }
  5976. rc = dsi_phy_validate_mode(ctrl->phy, &adj_mode.timing);
  5977. if (rc) {
  5978. DSI_ERR("[%s] phy mode validation failed, rc=%d\n",
  5979. display->name, rc);
  5980. goto error;
  5981. }
  5982. }
  5983. if ((flags & DSI_VALIDATE_FLAG_ALLOW_ADJUST) &&
  5984. (mode->dsi_mode_flags & DSI_MODE_FLAG_SEAMLESS)) {
  5985. rc = dsi_display_validate_mode_seamless(display, mode);
  5986. if (rc) {
  5987. DSI_ERR("[%s] seamless not possible rc=%d\n",
  5988. display->name, rc);
  5989. goto error;
  5990. }
  5991. }
  5992. error:
  5993. mutex_unlock(&display->display_lock);
  5994. return rc;
  5995. }
  5996. int dsi_display_set_mode(struct dsi_display *display,
  5997. struct dsi_display_mode *mode,
  5998. u32 flags)
  5999. {
  6000. int rc = 0;
  6001. struct dsi_display_mode adj_mode;
  6002. struct dsi_mode_info timing;
  6003. if (!display || !mode || !display->panel) {
  6004. DSI_ERR("Invalid params\n");
  6005. return -EINVAL;
  6006. }
  6007. mutex_lock(&display->display_lock);
  6008. adj_mode = *mode;
  6009. timing = adj_mode.timing;
  6010. adjust_timing_by_ctrl_count(display, &adj_mode);
  6011. if (!display->panel->cur_mode) {
  6012. display->panel->cur_mode =
  6013. kzalloc(sizeof(struct dsi_display_mode), GFP_KERNEL);
  6014. if (!display->panel->cur_mode) {
  6015. rc = -ENOMEM;
  6016. goto error;
  6017. }
  6018. }
  6019. /*For dynamic DSI setting, use specified clock rate */
  6020. if (display->cached_clk_rate > 0)
  6021. adj_mode.priv_info->clk_rate_hz = display->cached_clk_rate;
  6022. rc = dsi_display_validate_mode_set(display, &adj_mode, flags);
  6023. if (rc) {
  6024. DSI_ERR("[%s] mode cannot be set\n", display->name);
  6025. goto error;
  6026. }
  6027. rc = dsi_display_set_mode_sub(display, &adj_mode, flags);
  6028. if (rc) {
  6029. DSI_ERR("[%s] failed to set mode\n", display->name);
  6030. goto error;
  6031. }
  6032. DSI_INFO("mdp_transfer_time=%d, hactive=%d, vactive=%d, fps=%d\n",
  6033. adj_mode.priv_info->mdp_transfer_time_us,
  6034. timing.h_active, timing.v_active, timing.refresh_rate);
  6035. SDE_EVT32(adj_mode.priv_info->mdp_transfer_time_us,
  6036. timing.h_active, timing.v_active, timing.refresh_rate);
  6037. memcpy(display->panel->cur_mode, &adj_mode, sizeof(adj_mode));
  6038. error:
  6039. mutex_unlock(&display->display_lock);
  6040. return rc;
  6041. }
  6042. int dsi_display_set_tpg_state(struct dsi_display *display, bool enable)
  6043. {
  6044. int rc = 0;
  6045. int i;
  6046. struct dsi_display_ctrl *ctrl;
  6047. if (!display) {
  6048. DSI_ERR("Invalid params\n");
  6049. return -EINVAL;
  6050. }
  6051. display_for_each_ctrl(i, display) {
  6052. ctrl = &display->ctrl[i];
  6053. rc = dsi_ctrl_set_tpg_state(ctrl->ctrl, enable);
  6054. if (rc) {
  6055. DSI_ERR("[%s] failed to set tpg state for host_%d\n",
  6056. display->name, i);
  6057. goto error;
  6058. }
  6059. }
  6060. display->is_tpg_enabled = enable;
  6061. error:
  6062. return rc;
  6063. }
  6064. static int dsi_display_pre_switch(struct dsi_display *display)
  6065. {
  6066. int rc = 0;
  6067. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  6068. DSI_CORE_CLK, DSI_CLK_ON);
  6069. if (rc) {
  6070. DSI_ERR("[%s] failed to enable DSI core clocks, rc=%d\n",
  6071. display->name, rc);
  6072. goto error;
  6073. }
  6074. rc = dsi_display_ctrl_update(display);
  6075. if (rc) {
  6076. DSI_ERR("[%s] failed to update DSI controller, rc=%d\n",
  6077. display->name, rc);
  6078. goto error_ctrl_clk_off;
  6079. }
  6080. if (!display->trusted_vm_env) {
  6081. rc = dsi_display_set_clk_src(display);
  6082. if (rc) {
  6083. DSI_ERR(
  6084. "[%s] failed to set DSI link clock source, rc=%d\n",
  6085. display->name, rc);
  6086. goto error_ctrl_deinit;
  6087. }
  6088. }
  6089. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  6090. DSI_LINK_CLK, DSI_CLK_ON);
  6091. if (rc) {
  6092. DSI_ERR("[%s] failed to enable DSI link clocks, rc=%d\n",
  6093. display->name, rc);
  6094. goto error_ctrl_deinit;
  6095. }
  6096. goto error;
  6097. error_ctrl_deinit:
  6098. (void)dsi_display_ctrl_deinit(display);
  6099. error_ctrl_clk_off:
  6100. (void)dsi_display_clk_ctrl(display->dsi_clk_handle,
  6101. DSI_CORE_CLK, DSI_CLK_OFF);
  6102. error:
  6103. return rc;
  6104. }
  6105. static bool _dsi_display_validate_host_state(struct dsi_display *display)
  6106. {
  6107. int i;
  6108. struct dsi_display_ctrl *ctrl;
  6109. display_for_each_ctrl(i, display) {
  6110. ctrl = &display->ctrl[i];
  6111. if (!ctrl->ctrl)
  6112. continue;
  6113. if (!dsi_ctrl_validate_host_state(ctrl->ctrl))
  6114. return false;
  6115. }
  6116. return true;
  6117. }
  6118. static void dsi_display_handle_fifo_underflow(struct work_struct *work)
  6119. {
  6120. struct dsi_display *display = NULL;
  6121. display = container_of(work, struct dsi_display, fifo_underflow_work);
  6122. if (!display || !display->panel ||
  6123. atomic_read(&display->panel->esd_recovery_pending)) {
  6124. DSI_DEBUG("Invalid recovery use case\n");
  6125. return;
  6126. }
  6127. mutex_lock(&display->display_lock);
  6128. if (!_dsi_display_validate_host_state(display)) {
  6129. mutex_unlock(&display->display_lock);
  6130. return;
  6131. }
  6132. DSI_INFO("handle DSI FIFO underflow error\n");
  6133. SDE_EVT32(SDE_EVTLOG_FUNC_ENTRY);
  6134. dsi_display_clk_ctrl(display->dsi_clk_handle,
  6135. DSI_ALL_CLKS, DSI_CLK_ON);
  6136. dsi_display_soft_reset(display);
  6137. dsi_display_clk_ctrl(display->dsi_clk_handle,
  6138. DSI_ALL_CLKS, DSI_CLK_OFF);
  6139. SDE_EVT32(SDE_EVTLOG_FUNC_EXIT);
  6140. mutex_unlock(&display->display_lock);
  6141. }
  6142. static void dsi_display_handle_fifo_overflow(struct work_struct *work)
  6143. {
  6144. struct dsi_display *display = NULL;
  6145. struct dsi_display_ctrl *ctrl;
  6146. int i, rc;
  6147. int mask = BIT(20); /* clock lane */
  6148. int (*cb_func)(void *event_usr_ptr,
  6149. uint32_t event_idx, uint32_t instance_idx,
  6150. uint32_t data0, uint32_t data1,
  6151. uint32_t data2, uint32_t data3);
  6152. void *data;
  6153. u32 version = 0;
  6154. display = container_of(work, struct dsi_display, fifo_overflow_work);
  6155. if (!display || !display->panel ||
  6156. (display->panel->panel_mode != DSI_OP_VIDEO_MODE) ||
  6157. atomic_read(&display->panel->esd_recovery_pending)) {
  6158. DSI_DEBUG("Invalid recovery use case\n");
  6159. return;
  6160. }
  6161. mutex_lock(&display->display_lock);
  6162. if (!_dsi_display_validate_host_state(display)) {
  6163. mutex_unlock(&display->display_lock);
  6164. return;
  6165. }
  6166. DSI_INFO("handle DSI FIFO overflow error\n");
  6167. SDE_EVT32(SDE_EVTLOG_FUNC_ENTRY);
  6168. dsi_display_clk_ctrl(display->dsi_clk_handle,
  6169. DSI_ALL_CLKS, DSI_CLK_ON);
  6170. /*
  6171. * below recovery sequence is not applicable to
  6172. * hw version 2.0.0, 2.1.0 and 2.2.0, so return early.
  6173. */
  6174. ctrl = &display->ctrl[display->clk_master_idx];
  6175. version = dsi_ctrl_get_hw_version(ctrl->ctrl);
  6176. if (!version || (version < 0x20020001))
  6177. goto end;
  6178. /* reset ctrl and lanes */
  6179. display_for_each_ctrl(i, display) {
  6180. ctrl = &display->ctrl[i];
  6181. rc = dsi_ctrl_reset(ctrl->ctrl, mask);
  6182. rc = dsi_phy_lane_reset(ctrl->phy);
  6183. }
  6184. /* wait for display line count to be in active area */
  6185. ctrl = &display->ctrl[display->clk_master_idx];
  6186. if (ctrl->ctrl->recovery_cb.event_cb) {
  6187. cb_func = ctrl->ctrl->recovery_cb.event_cb;
  6188. data = ctrl->ctrl->recovery_cb.event_usr_ptr;
  6189. rc = cb_func(data, SDE_CONN_EVENT_VID_FIFO_OVERFLOW,
  6190. display->clk_master_idx, 0, 0, 0, 0);
  6191. if (rc < 0) {
  6192. DSI_DEBUG("sde callback failed\n");
  6193. goto end;
  6194. }
  6195. }
  6196. /* Enable Video mode for DSI controller */
  6197. display_for_each_ctrl(i, display) {
  6198. ctrl = &display->ctrl[i];
  6199. dsi_ctrl_vid_engine_en(ctrl->ctrl, true);
  6200. }
  6201. /*
  6202. * Add sufficient delay to make sure
  6203. * pixel transmission has started
  6204. */
  6205. udelay(200);
  6206. end:
  6207. dsi_display_clk_ctrl(display->dsi_clk_handle,
  6208. DSI_ALL_CLKS, DSI_CLK_OFF);
  6209. SDE_EVT32(SDE_EVTLOG_FUNC_EXIT);
  6210. mutex_unlock(&display->display_lock);
  6211. }
  6212. static void dsi_display_handle_lp_rx_timeout(struct work_struct *work)
  6213. {
  6214. struct dsi_display *display = NULL;
  6215. struct dsi_display_ctrl *ctrl;
  6216. int i, rc;
  6217. int mask = (BIT(20) | (0xF << 16)); /* clock lane and 4 data lane */
  6218. int (*cb_func)(void *event_usr_ptr,
  6219. uint32_t event_idx, uint32_t instance_idx,
  6220. uint32_t data0, uint32_t data1,
  6221. uint32_t data2, uint32_t data3);
  6222. void *data;
  6223. u32 version = 0;
  6224. display = container_of(work, struct dsi_display, lp_rx_timeout_work);
  6225. if (!display || !display->panel ||
  6226. (display->panel->panel_mode != DSI_OP_VIDEO_MODE) ||
  6227. atomic_read(&display->panel->esd_recovery_pending)) {
  6228. DSI_DEBUG("Invalid recovery use case\n");
  6229. return;
  6230. }
  6231. mutex_lock(&display->display_lock);
  6232. if (!_dsi_display_validate_host_state(display)) {
  6233. mutex_unlock(&display->display_lock);
  6234. return;
  6235. }
  6236. DSI_INFO("handle DSI LP RX Timeout error\n");
  6237. SDE_EVT32(SDE_EVTLOG_FUNC_ENTRY);
  6238. dsi_display_clk_ctrl(display->dsi_clk_handle,
  6239. DSI_ALL_CLKS, DSI_CLK_ON);
  6240. /*
  6241. * below recovery sequence is not applicable to
  6242. * hw version 2.0.0, 2.1.0 and 2.2.0, so return early.
  6243. */
  6244. ctrl = &display->ctrl[display->clk_master_idx];
  6245. version = dsi_ctrl_get_hw_version(ctrl->ctrl);
  6246. if (!version || (version < 0x20020001))
  6247. goto end;
  6248. /* reset ctrl and lanes */
  6249. display_for_each_ctrl(i, display) {
  6250. ctrl = &display->ctrl[i];
  6251. rc = dsi_ctrl_reset(ctrl->ctrl, mask);
  6252. rc = dsi_phy_lane_reset(ctrl->phy);
  6253. }
  6254. ctrl = &display->ctrl[display->clk_master_idx];
  6255. if (ctrl->ctrl->recovery_cb.event_cb) {
  6256. cb_func = ctrl->ctrl->recovery_cb.event_cb;
  6257. data = ctrl->ctrl->recovery_cb.event_usr_ptr;
  6258. rc = cb_func(data, SDE_CONN_EVENT_VID_FIFO_OVERFLOW,
  6259. display->clk_master_idx, 0, 0, 0, 0);
  6260. if (rc < 0) {
  6261. DSI_DEBUG("Target is in suspend/shutdown\n");
  6262. goto end;
  6263. }
  6264. }
  6265. /* Enable Video mode for DSI controller */
  6266. display_for_each_ctrl(i, display) {
  6267. ctrl = &display->ctrl[i];
  6268. dsi_ctrl_vid_engine_en(ctrl->ctrl, true);
  6269. }
  6270. /*
  6271. * Add sufficient delay to make sure
  6272. * pixel transmission as started
  6273. */
  6274. udelay(200);
  6275. end:
  6276. dsi_display_clk_ctrl(display->dsi_clk_handle,
  6277. DSI_ALL_CLKS, DSI_CLK_OFF);
  6278. SDE_EVT32(SDE_EVTLOG_FUNC_EXIT);
  6279. mutex_unlock(&display->display_lock);
  6280. }
  6281. static int dsi_display_cb_error_handler(void *data,
  6282. uint32_t event_idx, uint32_t instance_idx,
  6283. uint32_t data0, uint32_t data1,
  6284. uint32_t data2, uint32_t data3)
  6285. {
  6286. struct dsi_display *display = data;
  6287. if (!display || !(display->err_workq))
  6288. return -EINVAL;
  6289. switch (event_idx) {
  6290. case DSI_FIFO_UNDERFLOW:
  6291. queue_work(display->err_workq, &display->fifo_underflow_work);
  6292. break;
  6293. case DSI_FIFO_OVERFLOW:
  6294. queue_work(display->err_workq, &display->fifo_overflow_work);
  6295. break;
  6296. case DSI_LP_Rx_TIMEOUT:
  6297. queue_work(display->err_workq, &display->lp_rx_timeout_work);
  6298. break;
  6299. default:
  6300. DSI_WARN("unhandled error interrupt: %d\n", event_idx);
  6301. break;
  6302. }
  6303. return 0;
  6304. }
  6305. static void dsi_display_register_error_handler(struct dsi_display *display)
  6306. {
  6307. int i = 0;
  6308. struct dsi_display_ctrl *ctrl;
  6309. struct dsi_event_cb_info event_info;
  6310. if (!display)
  6311. return;
  6312. display->err_workq = create_singlethread_workqueue("dsi_err_workq");
  6313. if (!display->err_workq) {
  6314. DSI_ERR("failed to create dsi workq!\n");
  6315. return;
  6316. }
  6317. INIT_WORK(&display->fifo_underflow_work,
  6318. dsi_display_handle_fifo_underflow);
  6319. INIT_WORK(&display->fifo_overflow_work,
  6320. dsi_display_handle_fifo_overflow);
  6321. INIT_WORK(&display->lp_rx_timeout_work,
  6322. dsi_display_handle_lp_rx_timeout);
  6323. memset(&event_info, 0, sizeof(event_info));
  6324. event_info.event_cb = dsi_display_cb_error_handler;
  6325. event_info.event_usr_ptr = display;
  6326. display_for_each_ctrl(i, display) {
  6327. ctrl = &display->ctrl[i];
  6328. ctrl->ctrl->irq_info.irq_err_cb = event_info;
  6329. }
  6330. }
  6331. static void dsi_display_unregister_error_handler(struct dsi_display *display)
  6332. {
  6333. int i = 0;
  6334. struct dsi_display_ctrl *ctrl;
  6335. if (!display)
  6336. return;
  6337. display_for_each_ctrl(i, display) {
  6338. ctrl = &display->ctrl[i];
  6339. memset(&ctrl->ctrl->irq_info.irq_err_cb,
  6340. 0, sizeof(struct dsi_event_cb_info));
  6341. }
  6342. if (display->err_workq) {
  6343. destroy_workqueue(display->err_workq);
  6344. display->err_workq = NULL;
  6345. }
  6346. }
  6347. int dsi_display_prepare(struct dsi_display *display)
  6348. {
  6349. int rc = 0;
  6350. struct dsi_display_mode *mode;
  6351. if (!display) {
  6352. DSI_ERR("Invalid params\n");
  6353. return -EINVAL;
  6354. }
  6355. if (!display->panel->cur_mode) {
  6356. DSI_ERR("no valid mode set for the display\n");
  6357. return -EINVAL;
  6358. }
  6359. SDE_EVT32(SDE_EVTLOG_FUNC_ENTRY);
  6360. mutex_lock(&display->display_lock);
  6361. mode = display->panel->cur_mode;
  6362. dsi_display_set_ctrl_esd_check_flag(display, false);
  6363. /* Set up ctrl isr before enabling core clk */
  6364. if (!display->trusted_vm_env)
  6365. dsi_display_ctrl_isr_configure(display, true);
  6366. if (mode->dsi_mode_flags & DSI_MODE_FLAG_DMS) {
  6367. if (display->is_cont_splash_enabled &&
  6368. display->config.panel_mode == DSI_OP_VIDEO_MODE) {
  6369. DSI_ERR("DMS not supported on first frame\n");
  6370. rc = -EINVAL;
  6371. goto error;
  6372. }
  6373. if (!is_skip_op_required(display)) {
  6374. /* update dsi ctrl for new mode */
  6375. rc = dsi_display_pre_switch(display);
  6376. if (rc)
  6377. DSI_ERR("[%s] panel pre-switch failed, rc=%d\n",
  6378. display->name, rc);
  6379. goto error;
  6380. }
  6381. }
  6382. if (!display->poms_pending &&
  6383. (!is_skip_op_required(display))) {
  6384. /*
  6385. * For continuous splash/trusted vm, we skip panel
  6386. * pre prepare since the regulator vote is already
  6387. * taken care in splash resource init
  6388. */
  6389. rc = dsi_panel_pre_prepare(display->panel);
  6390. if (rc) {
  6391. DSI_ERR("[%s] panel pre-prepare failed, rc=%d\n",
  6392. display->name, rc);
  6393. goto error;
  6394. }
  6395. }
  6396. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  6397. DSI_CORE_CLK, DSI_CLK_ON);
  6398. if (rc) {
  6399. DSI_ERR("[%s] failed to enable DSI core clocks, rc=%d\n",
  6400. display->name, rc);
  6401. goto error_panel_post_unprep;
  6402. }
  6403. /*
  6404. * If ULPS during suspend feature is enabled, then DSI PHY was
  6405. * left on during suspend. In this case, we do not need to reset/init
  6406. * PHY. This would have already been done when the CORE clocks are
  6407. * turned on. However, if cont splash is disabled, the first time DSI
  6408. * is powered on, phy init needs to be done unconditionally.
  6409. */
  6410. if (!display->panel->ulps_suspend_enabled || !display->ulps_enabled) {
  6411. rc = dsi_display_phy_sw_reset(display);
  6412. if (rc) {
  6413. DSI_ERR("[%s] failed to reset phy, rc=%d\n",
  6414. display->name, rc);
  6415. goto error_ctrl_clk_off;
  6416. }
  6417. rc = dsi_display_phy_enable(display);
  6418. if (rc) {
  6419. DSI_ERR("[%s] failed to enable DSI PHY, rc=%d\n",
  6420. display->name, rc);
  6421. goto error_ctrl_clk_off;
  6422. }
  6423. }
  6424. if (!display->trusted_vm_env) {
  6425. rc = dsi_display_set_clk_src(display);
  6426. if (rc) {
  6427. DSI_ERR(
  6428. "[%s] failed to set DSI link clock source, rc=%d\n",
  6429. display->name, rc);
  6430. goto error_phy_disable;
  6431. }
  6432. }
  6433. rc = dsi_display_ctrl_init(display);
  6434. if (rc) {
  6435. DSI_ERR("[%s] failed to setup DSI controller, rc=%d\n",
  6436. display->name, rc);
  6437. goto error_phy_disable;
  6438. }
  6439. /* Set up DSI ERROR event callback */
  6440. dsi_display_register_error_handler(display);
  6441. rc = dsi_display_ctrl_host_enable(display);
  6442. if (rc) {
  6443. DSI_ERR("[%s] failed to enable DSI host, rc=%d\n",
  6444. display->name, rc);
  6445. goto error_ctrl_deinit;
  6446. }
  6447. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  6448. DSI_LINK_CLK, DSI_CLK_ON);
  6449. if (rc) {
  6450. DSI_ERR("[%s] failed to enable DSI link clocks, rc=%d\n",
  6451. display->name, rc);
  6452. goto error_host_engine_off;
  6453. }
  6454. if (!is_skip_op_required(display)) {
  6455. /*
  6456. * For continuous splash/trusted vm, skip panel prepare and
  6457. * ctl reset since the pnael and ctrl is already in active
  6458. * state and panel on commands are not needed
  6459. */
  6460. rc = dsi_display_soft_reset(display);
  6461. if (rc) {
  6462. DSI_ERR("[%s] failed soft reset, rc=%d\n",
  6463. display->name, rc);
  6464. goto error_ctrl_link_off;
  6465. }
  6466. if (!display->poms_pending) {
  6467. rc = dsi_panel_prepare(display->panel);
  6468. if (rc) {
  6469. DSI_ERR("[%s] panel prepare failed, rc=%d\n",
  6470. display->name, rc);
  6471. goto error_ctrl_link_off;
  6472. }
  6473. }
  6474. }
  6475. goto error;
  6476. error_ctrl_link_off:
  6477. (void)dsi_display_clk_ctrl(display->dsi_clk_handle,
  6478. DSI_LINK_CLK, DSI_CLK_OFF);
  6479. error_host_engine_off:
  6480. (void)dsi_display_ctrl_host_disable(display);
  6481. error_ctrl_deinit:
  6482. (void)dsi_display_ctrl_deinit(display);
  6483. error_phy_disable:
  6484. (void)dsi_display_phy_disable(display);
  6485. error_ctrl_clk_off:
  6486. (void)dsi_display_clk_ctrl(display->dsi_clk_handle,
  6487. DSI_CORE_CLK, DSI_CLK_OFF);
  6488. error_panel_post_unprep:
  6489. (void)dsi_panel_post_unprepare(display->panel);
  6490. error:
  6491. mutex_unlock(&display->display_lock);
  6492. SDE_EVT32(SDE_EVTLOG_FUNC_EXIT);
  6493. return rc;
  6494. }
  6495. static int dsi_display_calc_ctrl_roi(const struct dsi_display *display,
  6496. const struct dsi_display_ctrl *ctrl,
  6497. const struct msm_roi_list *req_rois,
  6498. struct dsi_rect *out_roi)
  6499. {
  6500. const struct dsi_rect *bounds = &ctrl->ctrl->mode_bounds;
  6501. struct dsi_display_mode *cur_mode;
  6502. struct msm_roi_caps *roi_caps;
  6503. struct dsi_rect req_roi = { 0 };
  6504. int rc = 0;
  6505. cur_mode = display->panel->cur_mode;
  6506. if (!cur_mode)
  6507. return 0;
  6508. roi_caps = &cur_mode->priv_info->roi_caps;
  6509. if (req_rois->num_rects > roi_caps->num_roi) {
  6510. DSI_ERR("request for %d rois greater than max %d\n",
  6511. req_rois->num_rects,
  6512. roi_caps->num_roi);
  6513. rc = -EINVAL;
  6514. goto exit;
  6515. }
  6516. /**
  6517. * if no rois, user wants to reset back to full resolution
  6518. * note: h_active is already divided by ctrl_count
  6519. */
  6520. if (!req_rois->num_rects) {
  6521. *out_roi = *bounds;
  6522. goto exit;
  6523. }
  6524. /* intersect with the bounds */
  6525. req_roi.x = req_rois->roi[0].x1;
  6526. req_roi.y = req_rois->roi[0].y1;
  6527. req_roi.w = req_rois->roi[0].x2 - req_rois->roi[0].x1;
  6528. req_roi.h = req_rois->roi[0].y2 - req_rois->roi[0].y1;
  6529. dsi_rect_intersect(&req_roi, bounds, out_roi);
  6530. exit:
  6531. /* adjust the ctrl origin to be top left within the ctrl */
  6532. out_roi->x = out_roi->x - bounds->x;
  6533. DSI_DEBUG("ctrl%d:%d: req (%d,%d,%d,%d) bnd (%d,%d,%d,%d) out (%d,%d,%d,%d)\n",
  6534. ctrl->dsi_ctrl_idx, ctrl->ctrl->cell_index,
  6535. req_roi.x, req_roi.y, req_roi.w, req_roi.h,
  6536. bounds->x, bounds->y, bounds->w, bounds->h,
  6537. out_roi->x, out_roi->y, out_roi->w, out_roi->h);
  6538. return rc;
  6539. }
  6540. static int dsi_display_qsync(struct dsi_display *display, bool enable)
  6541. {
  6542. int i;
  6543. int rc = 0;
  6544. if (!display->panel->qsync_caps.qsync_min_fps) {
  6545. DSI_ERR("%s:ERROR: qsync set, but no fps\n", __func__);
  6546. return 0;
  6547. }
  6548. mutex_lock(&display->display_lock);
  6549. display_for_each_ctrl(i, display) {
  6550. if (enable) {
  6551. /* send the commands to enable qsync */
  6552. rc = dsi_panel_send_qsync_on_dcs(display->panel, i);
  6553. if (rc) {
  6554. DSI_ERR("fail qsync ON cmds rc:%d\n", rc);
  6555. goto exit;
  6556. }
  6557. } else {
  6558. /* send the commands to enable qsync */
  6559. rc = dsi_panel_send_qsync_off_dcs(display->panel, i);
  6560. if (rc) {
  6561. DSI_ERR("fail qsync OFF cmds rc:%d\n", rc);
  6562. goto exit;
  6563. }
  6564. }
  6565. dsi_ctrl_setup_avr(display->ctrl[i].ctrl, enable);
  6566. }
  6567. exit:
  6568. SDE_EVT32(enable, display->panel->qsync_caps.qsync_min_fps, rc);
  6569. mutex_unlock(&display->display_lock);
  6570. return rc;
  6571. }
  6572. static int dsi_display_set_roi(struct dsi_display *display,
  6573. struct msm_roi_list *rois)
  6574. {
  6575. struct dsi_display_mode *cur_mode;
  6576. struct msm_roi_caps *roi_caps;
  6577. int rc = 0;
  6578. int i;
  6579. if (!display || !rois || !display->panel)
  6580. return -EINVAL;
  6581. cur_mode = display->panel->cur_mode;
  6582. if (!cur_mode)
  6583. return 0;
  6584. roi_caps = &cur_mode->priv_info->roi_caps;
  6585. if (!roi_caps->enabled)
  6586. return 0;
  6587. display_for_each_ctrl(i, display) {
  6588. struct dsi_display_ctrl *ctrl = &display->ctrl[i];
  6589. struct dsi_rect ctrl_roi;
  6590. bool changed = false;
  6591. rc = dsi_display_calc_ctrl_roi(display, ctrl, rois, &ctrl_roi);
  6592. if (rc) {
  6593. DSI_ERR("dsi_display_calc_ctrl_roi failed rc %d\n", rc);
  6594. return rc;
  6595. }
  6596. rc = dsi_ctrl_set_roi(ctrl->ctrl, &ctrl_roi, &changed);
  6597. if (rc) {
  6598. DSI_ERR("dsi_ctrl_set_roi failed rc %d\n", rc);
  6599. return rc;
  6600. }
  6601. if (!changed)
  6602. continue;
  6603. /* send the new roi to the panel via dcs commands */
  6604. rc = dsi_panel_send_roi_dcs(display->panel, i, &ctrl_roi);
  6605. if (rc) {
  6606. DSI_ERR("dsi_panel_set_roi failed rc %d\n", rc);
  6607. return rc;
  6608. }
  6609. /* re-program the ctrl with the timing based on the new roi */
  6610. rc = dsi_ctrl_timing_setup(ctrl->ctrl);
  6611. if (rc) {
  6612. DSI_ERR("dsi_ctrl_setup failed rc %d\n", rc);
  6613. return rc;
  6614. }
  6615. }
  6616. return rc;
  6617. }
  6618. int dsi_display_pre_kickoff(struct drm_connector *connector,
  6619. struct dsi_display *display,
  6620. struct msm_display_kickoff_params *params)
  6621. {
  6622. int rc = 0, ret = 0;
  6623. int i;
  6624. /* check and setup MISR */
  6625. if (display->misr_enable)
  6626. _dsi_display_setup_misr(display);
  6627. /* dynamic DSI clock setting */
  6628. if (atomic_read(&display->clkrate_change_pending)) {
  6629. mutex_lock(&display->display_lock);
  6630. /*
  6631. * acquire panel_lock to make sure no commands are in progress
  6632. */
  6633. dsi_panel_acquire_panel_lock(display->panel);
  6634. /*
  6635. * Wait for DSI command engine not to be busy sending data
  6636. * from display engine.
  6637. * If waiting fails, return "rc" instead of below "ret" so as
  6638. * not to impact DRM commit. The clock updating would be
  6639. * deferred to the next DRM commit.
  6640. */
  6641. display_for_each_ctrl(i, display) {
  6642. struct dsi_ctrl *ctrl = display->ctrl[i].ctrl;
  6643. ret = dsi_ctrl_wait_for_cmd_mode_mdp_idle(ctrl);
  6644. if (ret)
  6645. goto wait_failure;
  6646. }
  6647. /*
  6648. * Don't check the return value so as not to impact DRM commit
  6649. * when error occurs.
  6650. */
  6651. (void)dsi_display_force_update_dsi_clk(display);
  6652. wait_failure:
  6653. /* release panel_lock */
  6654. dsi_panel_release_panel_lock(display->panel);
  6655. mutex_unlock(&display->display_lock);
  6656. }
  6657. if (!ret)
  6658. rc = dsi_display_set_roi(display, params->rois);
  6659. return rc;
  6660. }
  6661. int dsi_display_config_ctrl_for_cont_splash(struct dsi_display *display)
  6662. {
  6663. int rc = 0;
  6664. if (!display || !display->panel) {
  6665. DSI_ERR("Invalid params\n");
  6666. return -EINVAL;
  6667. }
  6668. if (!display->panel->cur_mode) {
  6669. DSI_ERR("no valid mode set for the display\n");
  6670. return -EINVAL;
  6671. }
  6672. if (display->config.panel_mode == DSI_OP_VIDEO_MODE) {
  6673. rc = dsi_display_vid_engine_enable(display);
  6674. if (rc) {
  6675. DSI_ERR("[%s]failed to enable DSI video engine, rc=%d\n",
  6676. display->name, rc);
  6677. goto error_out;
  6678. }
  6679. } else if (display->config.panel_mode == DSI_OP_CMD_MODE) {
  6680. rc = dsi_display_cmd_engine_enable(display);
  6681. if (rc) {
  6682. DSI_ERR("[%s]failed to enable DSI cmd engine, rc=%d\n",
  6683. display->name, rc);
  6684. goto error_out;
  6685. }
  6686. } else {
  6687. DSI_ERR("[%s] Invalid configuration\n", display->name);
  6688. rc = -EINVAL;
  6689. }
  6690. error_out:
  6691. return rc;
  6692. }
  6693. int dsi_display_pre_commit(void *display,
  6694. struct msm_display_conn_params *params)
  6695. {
  6696. bool enable = false;
  6697. int rc = 0;
  6698. if (!display || !params) {
  6699. pr_err("Invalid params\n");
  6700. return -EINVAL;
  6701. }
  6702. if (params->qsync_update) {
  6703. enable = (params->qsync_mode > 0) ? true : false;
  6704. rc = dsi_display_qsync(display, enable);
  6705. if (rc)
  6706. pr_err("%s failed to send qsync commands\n",
  6707. __func__);
  6708. SDE_EVT32(params->qsync_mode, rc);
  6709. }
  6710. return rc;
  6711. }
  6712. static void dsi_display_panel_id_notification(struct dsi_display *display)
  6713. {
  6714. if (display->panel_id != ~0x0 &&
  6715. display->ctrl[0].ctrl->panel_id_cb.event_cb) {
  6716. display->ctrl[0].ctrl->panel_id_cb.event_cb(
  6717. display->ctrl[0].ctrl->panel_id_cb.event_usr_ptr,
  6718. display->ctrl[0].ctrl->panel_id_cb.event_idx,
  6719. 0, ((display->panel_id & 0xffffffff00000000) >> 31),
  6720. (display->panel_id & 0xffffffff), 0, 0);
  6721. }
  6722. }
  6723. int dsi_display_enable(struct dsi_display *display)
  6724. {
  6725. int rc = 0;
  6726. struct dsi_display_mode *mode;
  6727. if (!display || !display->panel) {
  6728. DSI_ERR("Invalid params\n");
  6729. return -EINVAL;
  6730. }
  6731. if (!display->panel->cur_mode) {
  6732. DSI_ERR("no valid mode set for the display\n");
  6733. return -EINVAL;
  6734. }
  6735. SDE_EVT32(SDE_EVTLOG_FUNC_ENTRY);
  6736. /*
  6737. * Engine states and panel states are populated during splash
  6738. * resource/trusted vm and hence we return early
  6739. */
  6740. if (is_skip_op_required(display)) {
  6741. dsi_display_config_ctrl_for_cont_splash(display);
  6742. rc = dsi_display_splash_res_cleanup(display);
  6743. if (rc) {
  6744. DSI_ERR("Continuous splash res cleanup failed, rc=%d\n",
  6745. rc);
  6746. return -EINVAL;
  6747. }
  6748. display->panel->panel_initialized = true;
  6749. DSI_DEBUG("cont splash enabled, display enable not required\n");
  6750. dsi_display_panel_id_notification(display);
  6751. return 0;
  6752. }
  6753. mutex_lock(&display->display_lock);
  6754. mode = display->panel->cur_mode;
  6755. if (mode->dsi_mode_flags & DSI_MODE_FLAG_DMS) {
  6756. rc = dsi_panel_post_switch(display->panel);
  6757. if (rc) {
  6758. DSI_ERR("[%s] failed to switch DSI panel mode, rc=%d\n",
  6759. display->name, rc);
  6760. goto error;
  6761. }
  6762. } else if (!display->poms_pending) {
  6763. rc = dsi_panel_enable(display->panel);
  6764. if (rc) {
  6765. DSI_ERR("[%s] failed to enable DSI panel, rc=%d\n",
  6766. display->name, rc);
  6767. goto error;
  6768. }
  6769. }
  6770. dsi_display_panel_id_notification(display);
  6771. /* Block sending pps command if modeset is due to fps difference */
  6772. if ((mode->priv_info->dsc_enabled ||
  6773. mode->priv_info->vdc_enabled) &&
  6774. !(mode->dsi_mode_flags & DSI_MODE_FLAG_DMS_FPS)) {
  6775. rc = dsi_panel_update_pps(display->panel);
  6776. if (rc) {
  6777. DSI_ERR("[%s] panel pps cmd update failed, rc=%d\n",
  6778. display->name, rc);
  6779. goto error;
  6780. }
  6781. }
  6782. if (mode->dsi_mode_flags & DSI_MODE_FLAG_DMS) {
  6783. rc = dsi_panel_switch(display->panel);
  6784. if (rc)
  6785. DSI_ERR("[%s] failed to switch DSI panel mode, rc=%d\n",
  6786. display->name, rc);
  6787. goto error;
  6788. }
  6789. if (display->config.panel_mode == DSI_OP_VIDEO_MODE) {
  6790. DSI_DEBUG("%s:enable video timing eng\n", __func__);
  6791. rc = dsi_display_vid_engine_enable(display);
  6792. if (rc) {
  6793. DSI_ERR("[%s]failed to enable DSI video engine, rc=%d\n",
  6794. display->name, rc);
  6795. goto error_disable_panel;
  6796. }
  6797. } else if (display->config.panel_mode == DSI_OP_CMD_MODE) {
  6798. DSI_DEBUG("%s:enable command timing eng\n", __func__);
  6799. rc = dsi_display_cmd_engine_enable(display);
  6800. if (rc) {
  6801. DSI_ERR("[%s]failed to enable DSI cmd engine, rc=%d\n",
  6802. display->name, rc);
  6803. goto error_disable_panel;
  6804. }
  6805. } else {
  6806. DSI_ERR("[%s] Invalid configuration\n", display->name);
  6807. rc = -EINVAL;
  6808. goto error_disable_panel;
  6809. }
  6810. goto error;
  6811. error_disable_panel:
  6812. (void)dsi_panel_disable(display->panel);
  6813. error:
  6814. mutex_unlock(&display->display_lock);
  6815. SDE_EVT32(SDE_EVTLOG_FUNC_EXIT);
  6816. return rc;
  6817. }
  6818. int dsi_display_post_enable(struct dsi_display *display)
  6819. {
  6820. int rc = 0;
  6821. if (!display) {
  6822. DSI_ERR("Invalid params\n");
  6823. return -EINVAL;
  6824. }
  6825. mutex_lock(&display->display_lock);
  6826. if (display->panel->cur_mode->dsi_mode_flags &
  6827. DSI_MODE_FLAG_POMS_TO_CMD) {
  6828. dsi_panel_switch_cmd_mode_in(display->panel);
  6829. } else if (display->panel->cur_mode->dsi_mode_flags &
  6830. DSI_MODE_FLAG_POMS_TO_VID)
  6831. dsi_panel_switch_video_mode_in(display->panel);
  6832. else {
  6833. rc = dsi_panel_post_enable(display->panel);
  6834. if (rc)
  6835. DSI_ERR("[%s] panel post-enable failed, rc=%d\n",
  6836. display->name, rc);
  6837. }
  6838. /* remove the clk vote for CMD mode panels */
  6839. if (display->config.panel_mode == DSI_OP_CMD_MODE)
  6840. dsi_display_clk_ctrl(display->dsi_clk_handle,
  6841. DSI_ALL_CLKS, DSI_CLK_OFF);
  6842. mutex_unlock(&display->display_lock);
  6843. return rc;
  6844. }
  6845. int dsi_display_pre_disable(struct dsi_display *display)
  6846. {
  6847. int rc = 0;
  6848. if (!display) {
  6849. DSI_ERR("Invalid params\n");
  6850. return -EINVAL;
  6851. }
  6852. mutex_lock(&display->display_lock);
  6853. /* enable the clk vote for CMD mode panels */
  6854. if (display->config.panel_mode == DSI_OP_CMD_MODE)
  6855. dsi_display_clk_ctrl(display->dsi_clk_handle,
  6856. DSI_ALL_CLKS, DSI_CLK_ON);
  6857. if (display->poms_pending) {
  6858. if (display->config.panel_mode == DSI_OP_CMD_MODE)
  6859. dsi_panel_switch_cmd_mode_out(display->panel);
  6860. if (display->config.panel_mode == DSI_OP_VIDEO_MODE) {
  6861. /*
  6862. * Add unbalanced vote for clock & cmd engine to enable
  6863. * async trigger of pre video to cmd mode switch.
  6864. */
  6865. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  6866. DSI_ALL_CLKS, DSI_CLK_ON);
  6867. if (rc) {
  6868. DSI_ERR("[%s]failed to enable all clocks,rc=%d",
  6869. display->name, rc);
  6870. goto exit;
  6871. }
  6872. rc = dsi_display_cmd_engine_enable(display);
  6873. if (rc) {
  6874. DSI_ERR("[%s]failed to enable cmd engine,rc=%d",
  6875. display->name, rc);
  6876. goto error_disable_clks;
  6877. }
  6878. dsi_panel_switch_video_mode_out(display->panel);
  6879. }
  6880. } else {
  6881. rc = dsi_panel_pre_disable(display->panel);
  6882. if (rc)
  6883. DSI_ERR("[%s] panel pre-disable failed, rc=%d\n",
  6884. display->name, rc);
  6885. }
  6886. goto exit;
  6887. error_disable_clks:
  6888. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  6889. DSI_ALL_CLKS, DSI_CLK_OFF);
  6890. if (rc)
  6891. DSI_ERR("[%s] failed to disable all DSI clocks, rc=%d\n",
  6892. display->name, rc);
  6893. exit:
  6894. mutex_unlock(&display->display_lock);
  6895. return rc;
  6896. }
  6897. static void dsi_display_handle_poms_te(struct work_struct *work)
  6898. {
  6899. struct dsi_display *display = NULL;
  6900. struct delayed_work *dw = to_delayed_work(work);
  6901. struct mipi_dsi_device *dsi = NULL;
  6902. struct dsi_panel *panel = NULL;
  6903. int rc = 0;
  6904. display = container_of(dw, struct dsi_display, poms_te_work);
  6905. if (!display || !display->panel) {
  6906. DSI_ERR("Invalid params\n");
  6907. return;
  6908. }
  6909. panel = display->panel;
  6910. mutex_lock(&panel->panel_lock);
  6911. if (!dsi_panel_initialized(panel)) {
  6912. rc = -EINVAL;
  6913. goto error;
  6914. }
  6915. dsi = &panel->mipi_device;
  6916. rc = mipi_dsi_dcs_set_tear_off(dsi);
  6917. error:
  6918. mutex_unlock(&panel->panel_lock);
  6919. if (rc < 0)
  6920. DSI_ERR("failed to set tear off\n");
  6921. }
  6922. int dsi_display_disable(struct dsi_display *display)
  6923. {
  6924. int rc = 0;
  6925. if (!display) {
  6926. DSI_ERR("Invalid params\n");
  6927. return -EINVAL;
  6928. }
  6929. SDE_EVT32(SDE_EVTLOG_FUNC_ENTRY);
  6930. mutex_lock(&display->display_lock);
  6931. /* cancel delayed work */
  6932. if (display->poms_pending &&
  6933. display->panel->poms_align_vsync)
  6934. cancel_delayed_work_sync(&display->poms_te_work);
  6935. rc = dsi_display_wake_up(display);
  6936. if (rc)
  6937. DSI_ERR("[%s] display wake up failed, rc=%d\n",
  6938. display->name, rc);
  6939. if (display->config.panel_mode == DSI_OP_VIDEO_MODE) {
  6940. rc = dsi_display_vid_engine_disable(display);
  6941. if (rc)
  6942. DSI_ERR("[%s]failed to disable DSI vid engine, rc=%d\n",
  6943. display->name, rc);
  6944. } else if (display->config.panel_mode == DSI_OP_CMD_MODE) {
  6945. /**
  6946. * On POMS request , disable panel TE through
  6947. * delayed work queue.
  6948. */
  6949. if (display->poms_pending &&
  6950. display->panel->poms_align_vsync) {
  6951. INIT_DELAYED_WORK(&display->poms_te_work,
  6952. dsi_display_handle_poms_te);
  6953. queue_delayed_work(system_wq,
  6954. &display->poms_te_work,
  6955. msecs_to_jiffies(100));
  6956. }
  6957. rc = dsi_display_cmd_engine_disable(display);
  6958. if (rc)
  6959. DSI_ERR("[%s]failed to disable DSI cmd engine, rc=%d\n",
  6960. display->name, rc);
  6961. } else {
  6962. DSI_ERR("[%s] Invalid configuration\n", display->name);
  6963. rc = -EINVAL;
  6964. }
  6965. if (!display->poms_pending && !is_skip_op_required(display)) {
  6966. rc = dsi_panel_disable(display->panel);
  6967. if (rc)
  6968. DSI_ERR("[%s] failed to disable DSI panel, rc=%d\n",
  6969. display->name, rc);
  6970. }
  6971. if (is_skip_op_required(display)) {
  6972. /* applicable only for trusted vm */
  6973. display->panel->panel_initialized = false;
  6974. display->panel->power_mode = SDE_MODE_DPMS_OFF;
  6975. }
  6976. mutex_unlock(&display->display_lock);
  6977. SDE_EVT32(SDE_EVTLOG_FUNC_EXIT);
  6978. return rc;
  6979. }
  6980. int dsi_display_update_pps(char *pps_cmd, void *disp)
  6981. {
  6982. struct dsi_display *display;
  6983. if (pps_cmd == NULL || disp == NULL) {
  6984. DSI_ERR("Invalid parameter\n");
  6985. return -EINVAL;
  6986. }
  6987. display = disp;
  6988. mutex_lock(&display->display_lock);
  6989. memcpy(display->panel->dce_pps_cmd, pps_cmd, DSI_CMD_PPS_SIZE);
  6990. mutex_unlock(&display->display_lock);
  6991. return 0;
  6992. }
  6993. int dsi_display_dump_clks_state(struct dsi_display *display)
  6994. {
  6995. int rc = 0;
  6996. if (!display) {
  6997. DSI_ERR("invalid display argument\n");
  6998. return -EINVAL;
  6999. }
  7000. if (!display->clk_mngr) {
  7001. DSI_ERR("invalid clk manager\n");
  7002. return -EINVAL;
  7003. }
  7004. if (!display->dsi_clk_handle || !display->mdp_clk_handle) {
  7005. DSI_ERR("invalid clk handles\n");
  7006. return -EINVAL;
  7007. }
  7008. mutex_lock(&display->display_lock);
  7009. rc = dsi_display_dump_clk_handle_state(display->dsi_clk_handle);
  7010. if (rc) {
  7011. DSI_ERR("failed to dump dsi clock state\n");
  7012. goto end;
  7013. }
  7014. rc = dsi_display_dump_clk_handle_state(display->mdp_clk_handle);
  7015. if (rc) {
  7016. DSI_ERR("failed to dump mdp clock state\n");
  7017. goto end;
  7018. }
  7019. end:
  7020. mutex_unlock(&display->display_lock);
  7021. return rc;
  7022. }
  7023. int dsi_display_unprepare(struct dsi_display *display)
  7024. {
  7025. int rc = 0, i;
  7026. struct dsi_display_ctrl *ctrl;
  7027. if (!display) {
  7028. DSI_ERR("Invalid params\n");
  7029. return -EINVAL;
  7030. }
  7031. SDE_EVT32(SDE_EVTLOG_FUNC_ENTRY);
  7032. mutex_lock(&display->display_lock);
  7033. rc = dsi_display_wake_up(display);
  7034. if (rc)
  7035. DSI_ERR("[%s] display wake up failed, rc=%d\n",
  7036. display->name, rc);
  7037. if (!display->poms_pending && !is_skip_op_required(display)) {
  7038. rc = dsi_panel_unprepare(display->panel);
  7039. if (rc)
  7040. DSI_ERR("[%s] panel unprepare failed, rc=%d\n",
  7041. display->name, rc);
  7042. }
  7043. /* Remove additional vote added for pre_mode_switch_to_cmd */
  7044. if (display->poms_pending &&
  7045. display->config.panel_mode == DSI_OP_VIDEO_MODE) {
  7046. display_for_each_ctrl(i, display) {
  7047. ctrl = &display->ctrl[i];
  7048. if (!ctrl->ctrl || !ctrl->ctrl->dma_wait_queued)
  7049. continue;
  7050. flush_workqueue(display->dma_cmd_workq);
  7051. cancel_work_sync(&ctrl->ctrl->dma_cmd_wait);
  7052. ctrl->ctrl->dma_wait_queued = false;
  7053. }
  7054. dsi_display_cmd_engine_disable(display);
  7055. dsi_display_clk_ctrl(display->dsi_clk_handle,
  7056. DSI_ALL_CLKS, DSI_CLK_OFF);
  7057. }
  7058. rc = dsi_display_ctrl_host_disable(display);
  7059. if (rc)
  7060. DSI_ERR("[%s] failed to disable DSI host, rc=%d\n",
  7061. display->name, rc);
  7062. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  7063. DSI_LINK_CLK, DSI_CLK_OFF);
  7064. if (rc)
  7065. DSI_ERR("[%s] failed to disable Link clocks, rc=%d\n",
  7066. display->name, rc);
  7067. rc = dsi_display_ctrl_deinit(display);
  7068. if (rc)
  7069. DSI_ERR("[%s] failed to deinit controller, rc=%d\n",
  7070. display->name, rc);
  7071. if (!display->panel->ulps_suspend_enabled) {
  7072. rc = dsi_display_phy_disable(display);
  7073. if (rc)
  7074. DSI_ERR("[%s] failed to disable DSI PHY, rc=%d\n",
  7075. display->name, rc);
  7076. }
  7077. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  7078. DSI_CORE_CLK, DSI_CLK_OFF);
  7079. if (rc)
  7080. DSI_ERR("[%s] failed to disable DSI clocks, rc=%d\n",
  7081. display->name, rc);
  7082. /* destrory dsi isr set up */
  7083. dsi_display_ctrl_isr_configure(display, false);
  7084. if (!display->poms_pending && !is_skip_op_required(display)) {
  7085. rc = dsi_panel_post_unprepare(display->panel);
  7086. if (rc)
  7087. DSI_ERR("[%s] panel post-unprepare failed, rc=%d\n",
  7088. display->name, rc);
  7089. }
  7090. mutex_unlock(&display->display_lock);
  7091. /* Free up DSI ERROR event callback */
  7092. dsi_display_unregister_error_handler(display);
  7093. SDE_EVT32(SDE_EVTLOG_FUNC_EXIT);
  7094. return rc;
  7095. }
  7096. void __init dsi_display_register(void)
  7097. {
  7098. dsi_phy_drv_register();
  7099. dsi_ctrl_drv_register();
  7100. dsi_display_parse_boot_display_selection();
  7101. platform_driver_register(&dsi_display_driver);
  7102. }
  7103. void __exit dsi_display_unregister(void)
  7104. {
  7105. platform_driver_unregister(&dsi_display_driver);
  7106. dsi_ctrl_drv_unregister();
  7107. dsi_phy_drv_unregister();
  7108. }
  7109. module_param_string(dsi_display0, dsi_display_primary, MAX_CMDLINE_PARAM_LEN,
  7110. 0600);
  7111. MODULE_PARM_DESC(dsi_display0,
  7112. "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");
  7113. module_param_string(dsi_display1, dsi_display_secondary, MAX_CMDLINE_PARAM_LEN,
  7114. 0600);
  7115. MODULE_PARM_DESC(dsi_display1,
  7116. "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");