dsi_display.c 231 KB

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