dsi_display.c 218 KB

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