dsi_display.c 216 KB

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