dsi_display.c 210 KB

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