dsi_display.c 189 KB

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