dsi_display.c 204 KB

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