dsi_display.c 223 KB

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