dsi_display.c 187 KB

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