dsi_display.c 167 KB

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