dsi_display.c 176 KB

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