dsi_display.c 169 KB

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