dsi_display.c 175 KB

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