dsi_display.c 217 KB

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