dsi_display.c 216 KB

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