dsi_display.c 219 KB

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