dsi_display.c 219 KB

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