dsi_display.c 217 KB

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