dsi_display.c 218 KB

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