dsi_display.c 210 KB

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