dsi_display.c 168 KB

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