dsi_display.c 199 KB

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