dsi_display.c 217 KB

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