dsi_display.c 217 KB

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