dsi_display.c 225 KB

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